How do I update metadata for an existing Amazon S3 file?
You can't:
Each Amazon S3 object has data, a key, and metadata. Object key (or key name) uniquely identifies the object in a bucket. Object metadata is a set of name-value pairs. You can set object metadata at the time you upload it. After you upload the object, you cannot modify object metadata. The only way to modify object metadata is to make a copy of the object and set the metadata.
http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html
It is possible to change the metadata by performing an object copy (see How to update metadata using Amazon S3 SDK):
ObjectMetadata metadataCopy = new ObjectMetadata();
// copy previous metadata
metadataCopy.addUserMetadata("newmetadata", "newmetadatavalue");
CopyObjectRequest request = new CopyObjectRequest(bucketName, existingKey, bucketName, existingKey)
.withNewObjectMetadata(metadataCopy);
amazonS3Client.copyObject(request);
Whether this is philosophically an "update" is up to you to decide.
PHP Example
I understand this question was not PHP specific, but it may help someone as it is a top result on Google.
This will overwrite the existing object.
$client = new \Aws\S3\S3Client([
'version' => '2006-03-01',
'region' => 'BUCKET-REGION'
]);
$updateResponse = $client->copyObject([
'Key' => 'OBJECTKEY',
'Bucket' => 'MYBUCKET',
'CopySource' => 'MYBUCKET/OBJECTKEY',
'MetadataDirective' => 'REPLACE',
'Metadata' => [
'width' => 441,
'height' => 189
]
]);