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

一世执手 提交于 2019-12-05 06:15:11

As far as I can see in the docs, a setTags-method is only available on a bucket level and not on individual keys. Therefore you cannot set different tags to your uploaded file, but you would have to do this on the containing bucket.

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.

While S3 "tags" are only at the bucket-level, each key in a bucket can have arbitrary "metadata" associated with it, which are key-value pairs themselves. See the boto documentation:

k.set_metadata('key', 'value')
value = k.get_metadata('key') # prints 'value'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!