Skip to content

Instantly share code, notes, and snippets.

@CodeFreezr
Created September 24, 2019 17:27
Show Gist options
  • Save CodeFreezr/328317d761535e311b6012e44b3f77e7 to your computer and use it in GitHub Desktop.
Save CodeFreezr/328317d761535e311b6012e44b3f77e7 to your computer and use it in GitHub Desktop.
List all my S3 buckets and their size.
for bucket in $(aws s3api list-buckets --query "Buckets[].Name" --output text); do aws cloudwatch get-metric-statistics --namespace AWS/S3 --metric-name BucketSizeBytes --dimensions Name=BucketName,Value=$bucket Name=StorageType,Value=StandardStorage --start-time $(date --iso-8601)T00:00 --end-time $(date --iso-8601)T23:59 --period 86400 --statistic Maximum | echo $bucket: $(numfmt --to si $(jq -r ".Datapoints[0].Maximum // 0")); done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment