Created
October 16, 2020 13:32
-
-
Save mcindea/6b03b3071e613965d00e13f84aa7eb22 to your computer and use it in GitHub Desktop.
extracts size of S3 AWS Bucket from a list using cloudwatch
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/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