Skip to content

Instantly share code, notes, and snippets.

@leite08
Created July 19, 2024 03:56
Show Gist options
  • Save leite08/c45798ca7ec02a19fba7f1341b0adb33 to your computer and use it in GitHub Desktop.
Save leite08/c45798ca7ec02a19fba7f1341b0adb33 to your computer and use it in GitHub Desktop.
Calculate the storage used by an ECR repository
#!/bin/bash
# Based on https://stackoverflow.com/a/78081105/2099911
ECR_REPO=...
REGION=...
total_size=0
echo "Retrieving image details for $ECR_REPO..."
image_details=$(aws ecr describe-images --repository-name $ECR_REPO --region $REGION --no-cli-pager)
echo "Done; calculating the total size..."
for row in $(echo "${image_details}" | jq -c '.imageDetails[]'); do
size_bytes=$(echo "${row}" | jq -r '.imageSizeInBytes')
total_size_bytes=$((total_size_bytes + size_bytes))
done
total_size_gb=$(echo "scale=2; $total_size_bytes / (1024 * 1024 * 1024)" | bc)
echo "Total size of all images in $ECR_REPO: ${total_size_gb} GB"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment