Skip to content

Instantly share code, notes, and snippets.

@haitaoyao
Last active November 2, 2016 10:06
Show Gist options
  • Save haitaoyao/5770a2d9773d998fc94923a7b5cc5399 to your computer and use it in GitHub Desktop.
Save haitaoyao/5770a2d9773d998fc94923a7b5cc5399 to your computer and use it in GitHub Desktop.
get the estimated storage size of AWS buckets without listing all the objects
bucket_name=$1
[ -z "$bucket_name" ] && echo "usage: $0 bucket_name" && exit 1
start_time=`date +'%FT%T' -d '-3 days'`
end_time=`date +'%FT%T'`
aws cloudwatch --region cn-north-1 \
get-metric-statistics \
--namespace AWS/S3 \
--metric-name BucketSizeBytes \
--start-time $start_time \
--end-time $end_time \
--period 86400 \
--statistics Average \
--dimensions Name=BucketName,Value=$bucket_name\
Name=StorageType,Value=StandardStorage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment