for bucket in `aws s3api list-buckets --query "Buckets[].Name" --profile <profile_name> --output table| grep test | awk '{print $2}'`; do aws s3api put-bucket-tagging --bucket $bucket --tagging 'TagSet=[{Key=service_id,Value=111}, {Key=Environment, Value=test}]' --profile <profile_name>; done
Get Tags for each bucket:
for bucket in `aws s3api list-buckets --profile <profile_name> | jq .Buckets[].Name | tr -d \"`; do
tags=$(aws s3api get-bucket-tagging --bucket $bucket --profile <profile_name>| jq -c '.[][] | {(.Key): .Value}' | tr '\n' '\t')
echo $bucket '|' $tags