Skip to content

Instantly share code, notes, and snippets.

@nirbhabbarat
Created September 10, 2018 09:04
Show Gist options
  • Save nirbhabbarat/db13d9132f947b5684e5cfb91162c123 to your computer and use it in GitHub Desktop.
Save nirbhabbarat/db13d9132f947b5684e5cfb91162c123 to your computer and use it in GitHub Desktop.
Add Name tag to S3 bucket same as bucket name
import boto3
s3 = boto3.client('s3')
response = s3.list_buckets()
buckets = [bucket['Name'] for bucket in response['Buckets']]
for bucket in buckets:
print bucket
tag={'TagSet':[{'Key': 'Name', 'Value': bucket}]}
try:
response = s3.put_bucket_tagging(Bucket=bucket, Tagging=tag)
except:
print bucket + " - broken"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment