Search code examples
pythonamazon-web-servicesboto3

How to add tags to S3 buckets from a dataframe in python


I have a dataframe as follows:

bucket_name    tags
name1          tag1
name2          tag2
name3          tag3

I want to use the above to insert tags into the respective s3 bucket. How can I do this using boto3?


Solution

  • import boto3
    s3_client = boto3.client('s3')
    bucket_tags = {'bucket_name': 'tag',...}
    for bucket, tag in bucket_tags.items():
      response = s3_client.put_bucket_tagging(
                     Bucket = bucket,
                     Tagging={
                         'TagSet': [
                             {
                                'Key': 'mykey',
                                'Value': tag
                             },
                          ]
                      },
                )