Skip to content

Instantly share code, notes, and snippets.

@schen1628
Last active October 15, 2015 18:32
Show Gist options
  • Save schen1628/c3948ae79e2a88f40acb to your computer and use it in GitHub Desktop.
Save schen1628/c3948ae79e2a88f40acb to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# This script goes through each bucket in s3. It counts number of objects in a bucket and sum up their size.
# It also prints out the ACLs for the bucket.
#
for bucket in `aws s3 ls | awk '{print $3}'`
do
aws s3 ls s3://$bucket --recursive |
awk -v bucket=$bucket 'BEGIN {total=0}
BEGIN {count=0} {total+=$3} {count++}
END {print bucket"\t"count"\t"total/1024/1024/1024}'
aws s3api get-bucket-acl --bucket $bucket --output text
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment