Last active
June 10, 2020 15:34
-
-
Save Klaudioz/2477501add39cb3a5c04dd7e7ade62d9 to your computer and use it in GitHub Desktop.
This file contains 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 | |
# Get list of S3 buckets from AWS and cleaning the output | |
s3_bucket_list=$(aws s3api list-buckets --query "Buckets[].Name" | sed -e 's/[][]//g' -e 's/”//g' -e 's/,//g' -e '/^$/d' -e 's/^[ \t]*//;s/[ \t]*$//' -e 's/"//g') | |
# Loop through the list of S3 buckets and tag them | |
for bucket in $(echo "$s3_bucket_list") | |
do | |
echo "Tagging: ${bucket}" | |
aws s3api put-bucket-tagging --bucket "$bucket" --tagging "TagSet=[{Key=aws-cost-explorer,Value=$bucket}]" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment