Note that ECR Lifecycle Policies may be a better fit for you use case.
Batman's very capable side kick - deletes old ECR images.
Images stored in ECR incur monthly data storage charges, this means paying to store old images that are no longer in use. Also, AWS ECR has a default limit of 1000 images. Therefore, it is desirable to ensure the ECR repositories are kept clean of unused images.
Per Lambda invocation:
If you need to delete more than 100 images, rather than complicating this script so that it can paginate through all pages of images, we suggest you simply run the lambda multiple times.
Authenticate and get AWS credentials via your preferred CLI, you may need to export the environment variables directly
Update the environment variables in serverless.yml to match your setup
Update the repoNames
array in handler.js
to reflect the repositories you want to clean
Lint the function
$ npm run lint
Run Prettier
$ npm run prettier:check
Test the function
$ npm test
Deploy the function
# Describe REPO_NAMES at deploy time
$ REPO_NAMES="test_repo,test_repo_1,test_repo_2" AWS_ACCOUNT_ID=1234567890 npm run deploy
Tail cloudwatch logs
$ npm run tail-logs