Skip to content

A toolkit that helps you automatically deletes old Docker images from an AWS ECR repository, keeping only the latest N images.

License

Notifications You must be signed in to change notification settings

Frank-Gu-81/aws-ecr-image-cleaner

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS ECR Cleanup Tool

Overview

This GitHub Action automatically deletes old Docker images from an AWS ECR repository, keeping only the latest N images.

Features

✅ Fully automated cleanup
✅ Allows users to specify the number of images to retain
✅ Works with GitHub Actions

Usage

1. Add the Action to Your Workflow

Create a .github/workflows/cleanup.yml file:

name: Cleanup ECR Images

on:
  schedule:
    - cron: "0 0 * * 1"
  workflow_dispatch:

jobs:
  cleanup:
    runs-on: ubuntu-latest
    steps:
      - name: Cleanup Old Images
        uses: Frank-Gu-81/[email protected]
        with:
          repository-name: "ecr-repo-to-cleanup"
          keep-images: 3

2. Required GitHub Secrets

Secret Name Description
AWS_ROLE IAM Role with ECR permissions
AWS_REGION AWS region (e.g., us-east-1)

3. Permission Required

Your IAM role must have the following policies:

{
  "Effect": "Allow",
  "Action": ["ecr:DescribeImages", "ecr:BatchDeleteImage"],
  "Resource": "*"
}

About

A toolkit that helps you automatically deletes old Docker images from an AWS ECR repository, keeping only the latest N images.

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published