Skip to content

Instantly share code, notes, and snippets.

@yeisoncruz16
Created October 22, 2020 00:45
Show Gist options
  • Save yeisoncruz16/d409c819b355a2c8fec49e1fe445c571 to your computer and use it in GitHub Desktop.
Save yeisoncruz16/d409c819b355a2c8fec49e1fe445c571 to your computer and use it in GitHub Desktop.
Simple bash script
#!/bin/bash
ECR_REGION='us-east-1'
ECR_REPO='YOUR_REPO_GO_HERE'
IMAGES_TO_DELETE=$( aws ecr list-images --region $ECR_REGION --repository-name $ECR_REPO --filter "tagStatus=UNTAGGED" --query 'imageIds[*]' --output json )
if [ "$IMAGES_TO_DELETE" == [] ]
then
echo "--> There are no UnTagged Images <--";
else
aws ecr batch-delete-image --region $ECR_REGION --repository-name $ECR_REPO --image-ids "$IMAGES_TO_DELETE" || true
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment