Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save gotunandan/69b1cd4f5f88b3796310f3dd83c041a4 to your computer and use it in GitHub Desktop.
Save gotunandan/69b1cd4f5f88b3796310f3dd83c041a4 to your computer and use it in GitHub Desktop.
Print a list of aws buckets along with their tags
#!/bin/bash
# lists all buckets along with their tags in the following format:
# bucket_name | { tag_name: tag_value }
# depends on AWS CLI and JQ
for bucket in `aws s3api list-buckets | jq .Buckets[].Name | tr -d \"`; do
tags=$(aws s3api get-bucket-tagging --bucket $bucket | jq -c '.[][] | {(.Key): .Value}' | tr '\n' '\t')
echo $bucket '|' $tags
done
@gotunandan
Copy link
Author

for bucket in $(aws s3api list-buckets | jq .Buckets[].Name -r); do tags=$(aws s3api get-bucket-tagging --bucket $bucket | jq -c '.[][] | {(.Key): .Value}' | tr '\n' '\t') echo $bucket '|' $tags done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment