Last active
March 12, 2019 11:02
-
-
Save sgasser/7e2b472a8fbb01e17001284185a617c7 to your computer and use it in GitHub Desktop.
AWS S3 File Size and Count of ALL buckets
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 | |
| # | |
| # Download and run: | |
| # bash aws_s3_all_buckets.sh > aws_s3_all_buckets.csv | |
| # | |
| # Or call directly: | |
| # bash <(curl -s https://gist.githubusercontent.com/sgasser/7e2b472a8fbb01e17001284185a617c7/raw) > aws_s3_all_buckets.csv | |
| # get all buckets | |
| buckets=$(aws s3api list-buckets --query "Buckets[].Name" | jq -r '.[]') | |
| echo "name;size (GB);count;" | |
| for bucket in $buckets | |
| do | |
| echo -n "$bucket;" | |
| # print size | |
| aws s3api list-objects --bucket "$bucket" --output json --query "sum(Contents[].Size)" | awk '{ byte=$1 /1024/1024/1024; printf byte ";" }' | |
| # print count | |
| aws s3api list-objects --bucket "$bucket" --output json --query "length(Contents[])" | awk '{ count=$1; printf count ";" }' | |
| echo '' | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment