Skip to content

Instantly share code, notes, and snippets.

@riccardomc
Created May 31, 2018 13:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riccardomc/4b1381d156d59da37dae370e00b3722e to your computer and use it in GitHub Desktop.
Save riccardomc/4b1381d156d59da37dae370e00b3722e to your computer and use it in GitHub Desktop.
Quick and dirty script to check the number of images in ECR repositories and if there is an associated lifecycle policy
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
REPOS=$(aws ecr describe-repositories --query 'repositories[*].repositoryName' | jq -r '.[]')
for r in $REPOS ; do
printf $r
COLOR=$GREEN
IMAGES=$(aws ecr describe-images --repository-name $r --query 'imageDetails[*].imageDigest' | jq -r '.[]')
IMAGES_COUNT=$(echo $IMAGES | wc -w)
if [ $IMAGES_COUNT -gt 500 ] ; then
COLOR=$RED
fi
printf " ${COLOR}$IMAGES_COUNT ${NC}"
COLOR=$GREEN
POLICY='policy'
$(aws ecr get-lifecycle-policy --repository-name $r > /dev/null 2>&1)
if [ $? != 0 ] ; then
COLOR=$RED
POLICY='no_policy'
fi
printf "${COLOR}$POLICY${NC}\n"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment