Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ericpardee/aa41fa0b05603d075792c9ce8d4529a0 to your computer and use it in GitHub Desktop.
Save ericpardee/aa41fa0b05603d075792c9ce8d4529a0 to your computer and use it in GitHub Desktop.
find unused aws s3 buckets
# if there's no objects in bucket and it's not being used as a website, probably not being used.
for bucket in $(aws -p prod s3api list-buckets --query "Buckets[].Name" --output table | tail -n +4 | awk '{print $2}') ; do if [ `aws -p prod s3 ls $bucket | wc -m | awk '{print $1}'` = 0 ]; then aws -p prod s3api get-bucket-website --bucket $bucket > /dev/null 2>&1 ; ret=$? ; if [ $ret -ne 0 ] ; then echo "$bucket" ; fi ; fi ; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment