nib-health-funds / robin

AWS ECR cleaning super hero
MIT License
6 stars 3 forks source link
aws cost-control ecr ecr-repositories serverless serverless-framework

Robin

Note that ECR Lifecycle Policies may be a better fit for you use case.

cicd Dependencies

Batman's very capable side kick - deletes old ECR images.

Why Robin?

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.

What we delete currently:

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.

Usage

  1. Authenticate and get AWS credentials via your preferred CLI, you may need to export the environment variables directly

  2. Update the environment variables in serverless.yml to match your setup

  3. Update the repoNames array in handler.js to reflect the repositories you want to clean

  4. Lint the function

    $ npm run lint
  5. Run Prettier

    $ npm run prettier:check
  6. Test the function

    $ npm test
  7. 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
  8. Tail cloudwatch logs

    $ npm run tail-logs

TODO