Last active
December 10, 2018 04:56
-
-
Save abridgett/7615c1df69274f359ea86f18aa189219 to your computer and use it in GitHub Desktop.
s3_bucket_sizes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# Report S3 bucket sizes | |
get_bucket_size() { | |
bucket="$1" | |
today=$(date +"%Y-%m-%d") | |
if [ $(uname -s) = "Darwin" ]; then | |
yesterday=$(date -v-1d +"%Y-%m-%d") | |
else | |
yesterday=$(date -d yesterday +"%Y-%m-%d") | |
fi | |
aws cloudwatch get-metric-statistics --namespace AWS/S3 \ | |
--start-time $yesterday --end-time $today --period 86400 \ | |
--statistics Average --metric-name BucketSizeBytes \ | |
--dimensions Name=BucketName,Value="$bucket" \ | |
Name=StorageType,Value=StandardStorage \ | |
| awk '/DATAPOINTS/ {printf("%.2f GB", $2/1024/1024/1024)}' | |
} | |
buckets=$(s3cmd ls |awk '{sub("^s3://","",$3); print $3}') | |
for bucket in $buckets; do | |
echo "$bucket" $(get_bucket_size "$bucket") | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment