DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Cover image for Amazon ECR - Lifecycle Policy Rules
πŸš€  Vu Dao πŸš€
πŸš€ Vu Dao πŸš€

Posted on

Amazon ECR - Lifecycle Policy Rules

Lifecycle policies

  • Amazon ECR lifecycle policies enable you to specify the lifecycle management of images in a repository.
  • A lifecycle policy is a set of one or more rules, where each rule defines an action for Amazon ECR.
  • The actions apply to images that contain tags prefixed with the given strings. This allows the automation of cleaning up unused images, for example expiring images based on age or count.
  • You should expect that after creating a lifecycle policy the affected images are expired within 24 hours.

Usecase:

  • A project will have multiple branches to develop features, admin will setup pipeline jobs to trigger build and deploy for any commits to any branches.
  • Application is compiled and then packed into a docker image in order to push it to Amazon ECR (Elastic Container Registry). This will lead to thousands of images stored in ECR, so the images (except ones with tag release) should have life cycle to reduce cost of ECR

Example of setting life cycle policy rule for an ECR repository (it depends on how the image is tagged)

Rule 1 Remove images with prefix integration-* after 3 days, these images are created in integration branches and they are tagged eg. integration-api-1234
Alt Text

Rule 2 Remove images with prefix develop-* after 5 days
Alt Text

Result
Alt Text

Top comments (0)

🌚 Browsing with dark mode makes you a better developer by a factor of exactly 40.

It's a scientific fact.