Skip to main content

Delete old images tag inside ECR repository

Project description

ECR lifecycle (Alpha)

Delete old images inside ECR repository using python and boto3

python-logo

Pylint

Table of Contents generated with DocToc

Requirements

  • python3
  • pip3

Credentials

Credentials will be taken from your AWS_PROFILE in your terminal when you execute this python script.

$ aws configure
$ export AWS_PROFILE="myprofile" # will be set in the terminal where you'll execute the python script

Installation

This tool is available in pypip package, so you can install it using your command line:

$ pip3 install ecr-lifecycle

Usage

Dry run

$ ecr-lifecycle -a 90 -r eu-west-1 -n repository/test/repo_name -l INFO

Delete images

$ ecr-lifecycle -a 90 -r eu-west-1 -n repository/test/repo_name -l INFO -d

Parameters

  • -a: max age of the image(default: 30 days)
  • -r: aws region
  • -n: ECR repository name
  • -l: level info (default: INFO)
  • -d: (delete) execute the operation and delete images. Is destructive! Execute the cli first without '-d' in dry_run mode

Example

example

TO DO

You can store about 10mil images in a single ECR repository. Imagine, you have 2000mil images older than 90 days and you want to delete it. When you execute the program, the client of boto3 only returns a max of 1000 values, so you need to launch the program two times.

client = boto3.client('ecr', region_name=args.aws_region)
images = client.describe_images(
    repositoryName=args.repository_name,
    maxResults=1000, # here, limit of max results 1000
)

License

LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ecr-lifecycle-0.1.1.tar.gz (8.8 kB view hashes)

Uploaded Source

Built Distribution

ecr_lifecycle-0.1.1-py3-none-any.whl (10.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page