Skip to content

Instantly share code, notes, and snippets.

@abdmun8
Created January 13, 2022 13:14
Show Gist options
  • Save abdmun8/e958cf85185939dec70c8daadadbbf70 to your computer and use it in GitHub Desktop.
Save abdmun8/e958cf85185939dec70c8daadadbbf70 to your computer and use it in GitHub Desktop.
Delete untagged images on AWS Elastic Container Registry

Delete untagged images on AWS Elastic Container Registry

Example using ap-southeast-1 region

#!/bin/bash
REPOS=$(aws ecr describe-repositories --region ap-southeast-1 --query 'repositories[].repositoryName' --output text)
for repo in $REPOS; do
    TAGS=$(aws ecr list-images --region  ap-southeast-1 --repository-name $repo --filter tagStatus=UNTAGGED --query 'imageIds[].imageDigest' --output text)
    for tag in $TAGS; do
        echo “Deleting image: $tag”
        aws ecr batch-delete-image --region  ap-southeast-1 --repository-name $repo --image-ids imageDigest=$tag
    done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment