QubOps

Day 9 - ECR Cleanup

AWS Cost Optimisation Advent Calendar 2024

2 min read time

#aws #ecr #ecs

Welcome to day 9 of the unofficial AWS Cost Optimisation Advent Calendar 2024, where every day we will be sharing new tips or tricks to help you optimise your cloud costs before Christmas 2024.

Today's post is another quick change you can make to instantly make some savings and is relevant to companies who use containers, more specifically companies who host their images in Elastic Container Registry (ECR).

ECR is a fully managed container registry similar to Docker Hub that makes it easy for developers to host, store, manage, and deploy container images.

Over time, ECR can accumulate a large number of images, which can lead to increased storage costs.

In many cases older images can be recreated from source code so there is rarely a valid reason to keep images forever which is the default behaviour of ECR.

Lifecycle Policies

To help manage the lifecycle of images in ECR, you can use lifecycle policies.

Lifecycle policies allow you to define rules to automatically clean up images after a certain time period with the ability to have different rules based on tags.

For example, you could have a rule that deletes staging or test images after 3 days and a seperate rule to delete production images after 7 days.

To create a lifecycle policy, navigate to the ECR console, select the repository you want to create the policy for, and click on the Lifecycle Policy tab.

Conclusion

Unless there is a valid reason to keep ECR images, it is simply a waste of money to keep them hanging around indefinitely.

A little bit of housecleaning can go a long way in reducing your ECR storage costs.

See you tomorrow for the next tip!

To be one of the first to know when the next edition is published please follow us on LinkedIn, X or subscribe to the RSS feed.

Join our newsletter for Cost Optimization tips and tricks

By subscribing you agree to our Privacy Policy and provide consent to receive updates from our company.