In a perfect world, this wouldn't exist.
Amazon Elastic Container Registry (ECR) is a great service, but it lacks a few key features that would make it easier for end users. Specifically, some metrics around usage and limits are important for end users, so that you don't learn about the limits the hard way.
This project is a simple Python script that will query the AWS API and report on the following metrics:
- Total number of repositories
- Total number of images in each repository (default limit is 10k)
- Total size of all images in each repository
Ideally the ECR team should implement these (and any others) and then I can retire this project.
Go ahead and add your 👍 reaction to this issue to signal your desire for this feature.
Until then, you can run this script manually, or even better - run it as a Lambda function on a schedule.
While ECR does support Service Quotas integration, it's not granular enough to help operators figure out which repositories are using the most space, and when they might need to request a limit increase or handle the situation themselves.
Note: This assumes you have Poetry and Python 3.10 installed.
git clone https://github.com/miketheman/ecr-metrics.git
poetry install
ecr-metrics
A better solution is to run this as a Lambda function on a schedule.
- Create a new Lambda function
- Upload the
ecr-metrics.py
file as the function code - Set the handler to
ecr-metrics.lambda_handler
- Set the runtime to
Python 3.10
- Set the timeout to
5 minutes
or an interval you find acceptable - Set the memory to
128 MB
Note: The code assumes it runs in the region where you have repositories. Amazon ECR is a regional service, and the quotas are regional as well. Deploy the Lambda Function to each region in which you have repositories.
- Create a new CloudWatch Events rule
- Set the schedule to
rate(30 minutes)
- Add a target of the Lambda function you created above
This project is licensed under the MIT License. See the LICENSE file for details.
See TODO for a list of things that need to be done.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
This project is not affiliated with Amazon Web Services (AWS) or Amazon.