Skip to content

Instantly share code, notes, and snippets.

@mjaromi
Last active February 9, 2021 17:02
Show Gist options
  • Save mjaromi/471ab9dceb87dab898a1e920ca6aa882 to your computer and use it in GitHub Desktop.
Save mjaromi/471ab9dceb87dab898a1e920ca6aa882 to your computer and use it in GitHub Desktop.
Show size of UNTAGGED images per ECR repository
aws ecr describe-repositories | jq -r '.repositories[].repositoryName' | sort | while read repository; do
totalSizeOfUntagged=0
while read imageSizeInBytes; do
totalSizeOfUntagged=$((totalSizeOfUntagged + imageSizeInBytes))
done < <(aws ecr describe-images --repository-name ${repository} --filter tagStatus=UNTAGGED | jq -r '.imageDetails[].imageSizeInBytes')
if [[ ${totalSizeOfUntagged} -gt 0 ]]; then
echo -ne "${repository} - "
echo ${totalSizeOfUntagged} | awk '{ print $1/1024/1024 " MB" }'
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment