Last active
May 20, 2016 10:21
-
-
Save dgoguerra/f88fde8ef605e0eab9ed to your computer and use it in GitHub Desktop.
Obtain an AWS S3 bucket size
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
| bucket_name="BUCKET_NAME" | |
| aws s3api list-objects \ | |
| --bucket $bucket_name \ | |
| --region `aws s3api get-bucket-location --bucket $bucket_name --output text` \ | |
| --output json \ | |
| --query "[sum(Contents[].Size), length(Contents[])]" |
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
| # http://stackoverflow.com/a/21372023 | |
| getBucketRegion() { | |
| local bucket_name="$1" | |
| aws s3api get-bucket-location --bucket $bucket_name --output text | |
| } | |
| bucket_name="BUCKET_NAME" | |
| aws s3 ls "s3://$bucket_name" --region $(getBucketRegion "$bucket_name") --recursive \ | |
| | grep -v -E "(Bucket: |Prefix: |LastWriteTime|^$|--)" \ | |
| | awk 'BEGIN {total=0}{total+=$3}END{print total/1024/1024" MB"}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment