Skip to content

Instantly share code, notes, and snippets.

@mcindea
Created October 16, 2020 13:32
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 mcindea/6b03b3071e613965d00e13f84aa7eb22 to your computer and use it in GitHub Desktop.
Save mcindea/6b03b3071e613965d00e13f84aa7eb22 to your computer and use it in GitHub Desktop.
extracts size of S3 AWS Bucket from a list using cloudwatch
#!/bin/bash
# Execute as :
# ./s3_buckets_size.sh list.txt
# where list.txt is a list of all bucket
for bucket in `cat $1`;do
SIZE=$(aws cloudwatch get-metric-statistics --namespace AWS/S3 --start-time $(date +%Y-%m-%dT%H:%M:%S -d "00:00 last week") --end-time $(date +%Y-%m-%dT%H:%M:%S) --period 86400 --statistics Average --region eu-west-1 --metric-name BucketSizeBytes --dimensions Name=BucketName,Value=$bucket Name=StorageType,Value=StandardStorage | jq .Datapoints[].Average | tail -1)
echo $bucketname $(numfmt --to iec --format "%8.1f" ${SIZE:-"0"})
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment