Code Monkey home page Code Monkey logo

ecr-cleanup-lambda's Introduction

#Automated Image Cleanup for Amazon ECR The Python script and Lambda function described here help clean up images in Amazon ECR. The script looks for images that are not used in running Amazon ECS tasks that can be deleted. You can configure the script to print the image list first to confirm deletions, specify a region, or specify a number of images to keep for potential rollbacks.

Authenticate with AWS

Configuring the AWS Command Line Interface.

Use virtualenv for Python execution

To prevent any problems with your system Python version conflicting with the application, we recommend using virtualenv.

Install Python: pip install python 3

Install virtualenv:

$ pip install virtualenv
$ virtualenv -p PATH_TO_YOUR_PYTHON_3 cloudformtion
$ virtualenv ~/.virtualenvs/cloudformtion
$ source ~/.virtualenvs/cloudformtion/bin/activate

Generate the Lambda package

  1. CD to the folder that contains main.py.
  2. Run the following command: pip install -r requirements.txt -t {THE_FOLDER_PATH}
  3. Compress the contents of folder (not the folder).

Upload the package to Lambda

  1. Run the following command: aws lambda create-function --function-name {NAME_OF_FUNCTION} --runtime python2.7 --role {ARN_NUMBER} --handler main.handler --timeout 15 --zip-file fileb://{ZIP_FILE_PATH}

Send the package update to Lambda

  1. Run the following command:

    aws lambda update-function-code --function-name {NAME_OF_FUNCTION} --zip-file fileb://{ZIP_FILE_PATH}

Examples

Prints the images that are not used by running tasks and which are older than the last 100 versions, in all regions:

python main.py

Deletes the images that are not used by running tasks and which are older than the last 100 versions, in all regions:

python main.py –dryrun False

Deletes the images that are not used by running tasks and which are older than the last 20 versions (in each repository), in all regions:

python main.py –dryrun False –imagestokeep 20

Deletes the images that are not used by running tasks and which are older than the last 20 versions (in each repository), in Oregon only:

python main.py –dryrun False –imagestokeep 20 –region us-west-2

ecr-cleanup-lambda's People

Contributors

anshrma avatar taraspos avatar prayerslayer avatar jpeddicord avatar witsoej avatar dyroffk avatar nfvs avatar

Watchers

Sebastian Hillig avatar R. Kevin Nelson avatar James Cloos avatar Markus Hinsche avatar Jakub avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.