Skip to main content

Image Cleanup for Amazon ECR

The script removes stale ECR images. Although ECR offers lifecycle policies that serve a similar task, the logic this script implements cannot be achieved by using them.

The intention is to protect the set of images, that meet the criteria :

  • comes from a specified period, counting from the oldest significant tag,
  • counts no less than N-images, counting from the oldest significant tag (if less than N comes from the specified period).

Significant tags are those that are somehow meaningful for the release process, ie. 'dev', 'rc', 'prod', 'stable' and so on.

As the production/stable images are usually older than their development counterparts, using the oldest tag date as an anchor to calculate the protected period, means protecting some set of images that directly precede the current production release.

Example

The diagram below explains how script works, assuming:

  • protected period = one year,
  • protected count = 13,
  • significant tags = dev, rc, prod,
  • ecr repositories limited to: hello_world, other_ecr_repo.

example

By default, it runs in dry mode. To print what images will be removed, run:

python3 main.py --config <config_file.yaml>

with config file content:

- name: Flush untagged images older than 7 days, leave no less than 7 images
  protected_period: 7
  protected_count: 7
  significant_tags: '*'
  protected_repositories:
    - some_ignored_repository
- name: Protect images are that created for a year since a last significant tag, leave no less than 13 images
  protected_period: 365
  protected_count: 13
  significant_tags:
    - dev
    - rc
    - prod
    - latest
  repositories:
    - hello_world

When no repository list is provided, the script will iterate through all of the ECR repositories that are accessible by the AWS account used. To skip some repositories use protected_repositories option.

To actually remove the images, run:

python3 main.py --config <config_file.yaml> --apply

Metadata

Release files for aws-ecr-cleanup 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-ecr-cleanup 0.1.5
File Size Uploaded Provenance
aws-ecr-cleanup-0.1.5.tar.gz 44.3 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-ecr-cleanup 0.1.5
File Interpreter ABI Platform
aws_ecr_cleanup-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 76.6 kB

Release files / aws-ecr-cleanup-0.1.5.tar.gz

Download URL aws-ecr-cleanup-0.1.5.tar.gz
Size 44.3 kB
Tags Source
SHA-256 checksum
How to use checksums
518ffde12988e5873b59d658da79693ddf3e9328c3587c81a2ce99e6f778794b
BLAKE2b-256 checksum
How to use checksums
31f77fec1e93fb1b2138f0697f78fedd5ee63cc2da8515a337d75be111d96aa9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.2

Release files / aws_ecr_cleanup-0.1.5-py3-none-any.whl

Download URL aws_ecr_cleanup-0.1.5-py3-none-any.whl
Size 32.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc3b3421634f1235f15253f134f7bee9c001790d4e831c6981e4a1882416d1f7
BLAKE2b-256 checksum
How to use checksums
fca30afc9cb2c4ec95319ed08d2d670d42a9988fdb221c7b18e8f43985326516
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.2

Security for aws-ecr-cleanup 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page