Skip to content

Instantly share code, notes, and snippets.

@HarshadRanganathan
Created December 13, 2021 19:00
Show Gist options
  • Save HarshadRanganathan/077e80f34f52d0a1a0d1358292226312 to your computer and use it in GitHub Desktop.
Save HarshadRanganathan/077e80f34f52d0a1a0d1358292226312 to your computer and use it in GitHub Desktop.
Bash script to delete ECR images in a filtered repository
aws ecr describe-repositories --output text |
awk '{print $6}' |
while read line; do
if [[ $line == *"api"* ]]; then
aws ecr list-images --repository-name $line --query 'imageIds[*]' --output text
fi |
while read imageDigest imageTag; do
aws ecr batch-delete-image --repository-name $line --image-ids imageDigest=$imageDigest;
done;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment