Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I add a tag to a key in boto (Amazon S3)?

I am trying to tag a key that I've uploaded to S3. In the same below I just create a file from a string. Once I have they key, I'm not sure how to tag the file. I've tried Tag as well as TagSet.

from boto.s3.bucket import Bucket
from boto.s3.key import Key
from boto.s3.tagging import Tag, TagSet

k = Key(bucket)
k.key = 'foobar/somefilename'
k.set_contents_from_string('some data in file')

Tag(k, 'the_tag')
like image 801
statguy Avatar asked Apr 05 '13 06:04

statguy


1 Answers

S3 has since added object level tags. You can get and set them with boto3.

These are considerably more versatile than metadata:

  • They can be added and modified without copying the object.
  • They can be used as filters in lifecycle management rules.
  • They can be used to control access to objects.
like image 78
Hank Avatar answered Oct 03 '22 21:10

Hank