boto3 documentation does not clearly specify how to update the user metadata of an already existing S3 Object.
Advertisement
Answer
It can be done using the copy_from() method –
JavaScript
x
7
1
import boto3
2
3
s3 = boto3.resource('s3')
4
s3_object = s3.Object('bucket-name', 'key')
5
s3_object.metadata.update({'id':'value'})
6
s3_object.copy_from(CopySource={'Bucket':'bucket-name', 'Key':'key'}, Metadata=s3_object.metadata, MetadataDirective='REPLACE')
7