How Long Are Images Retained with fromImageAsset? #30
|
I noticed that the ECR repository created under the hood by nextjs-build.ts > fromImageAsset has nearly 100 images, some going back 3 months. This is surprising because I’ve completely redeployed the stack containing the Is this expected behavior? Does I’m considering adding lifecycle rules to manage retention or possibly overriding My goal is to keep usage and costs minimal, especially for non-production environments. I don't want all past images to persist. I'm more likely to take the last 2 weeks in non-prod. Thought I'd start by striking up a conversation and see if anyone has thoughts on this. |
Replies: 1 comment 1 reply
|
Hey @coltenkrauter! Great question. When you run To modify the lifecycle policy of the ECR repository created by CDK bootstrap, you can use the App Staging Synthesizer feature. Here's how to do it: [1] Alternatively, if you want to modify an existing bootstrap repository, you can use a custom stack: Important considerations: The default repository name is typically 'cdk-assets' Be careful not to set too aggressive cleanup rules as it might affect your CDK deployments Consider keeping: Recent images for rollback purposes Images currently in use by your applications A reasonable number of historical images for audit purposes Common lifecycle rules to consider: Cleanup of untagged images Retention of only N most recent images Age-based cleanup for older images Remember to deploy these changes carefully as they affect the repository that CDK uses for its own operations. It's recommended to start with conservative rules and adjust based on your needs. |
Hey @coltenkrauter! Great question. When you run
cdk bootstrapan ECR Repository is created which is used for all CDK related images. I think the default lifecycle policy conservatively keeps all images forever. However, you can edit this. See answer from Amazon Q Developer:To modify the lifecycle policy of the ECR repository created by CDK bootstrap, you can use the App Staging Synthesizer feature. Here's how to do it: [1]