How to update metadata of an existing object in AWS S3 using python boto3?

后端 未结 3 1020
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-01 14:19

boto3 documentation does not clearly specify how to update the user metadata of an already existing S3 Object.

3条回答
  •  无人及你
    2020-12-01 15:04

    It can be done using the copy_from() method -

    import boto3
    
    s3 = boto3.resource('s3')
    s3_object = s3.Object('bucket-name', 'key')
    s3_object.metadata.update({'id':'value'})
    s3_object.copy_from(CopySource={'Bucket':'bucket-name', 'Key':'key'}, Metadata=s3_object.metadata, MetadataDirective='REPLACE')
    

提交回复
热议问题