Managing Object Metadata
Simple Object Storage (or SOS) allows you to separate file metadata from data. Each object in a bucket can be tagged with key-value pairs. This metadata is presented through HTTP headers on SOS requests and responses.
Add Metadata
From the the Portal:
- Click on STORAGE in the main navigation.
- Select your bucket.
- Click on on the pencil icon of the object to edit.
- Click on on the Metadata tab.
You can add key-value pairs, assigned to the object you chose.
From the CLI:
We assume for this example that you are using aws s3 cli and the aws s3api
command.
The put-object
and copy-object
commands allow to specify metadata.
You can then use the option --metadata
to add metada
If you want to update an object’s existing metadata, you should use copy-object
and --metadata-directive REPLACE
(or COPY
) - note that when using copy-object
, the source and destination objects are the same.
$ aws s3api put-object \
--bucket <bucket> \
--key <key> \
--body <file> \
--metadata test=true,foo=bar
$ aws s3api copy-object \
--bucket <bucket> \
--copy-source <bucket/key> \
--key <key> \
--metadata test=true,foo=bar \
--metadata-directive REPLACE
View Metadata
From the Portal:
To view the metadata associated with an object, you need to edit the object:
- Click on STORAGE in the main navigation.
- Select your bucket.
- Click on on the pencil icon of the object to edit.
- Click on on the Metadata tab.
From the CLI:
We assume for this example that you are using aws s3 cli and the aws s3api
command.
The head-object
command will return information on an object, including its metadata.
$ aws s3api head-object --bucket deleteme --key mdata
{
"AcceptRanges": "bytes",
"LastModified": "2024-11-18T15:22:23+00:00",
"ContentLength": 0,
"ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"",
"ContentType": "application/binary",
"Metadata": {
"test": "true",
"foo": "bar"
}
}
You can see 2 key-value pairs for this object:
test
was set totrue
.foo
was set tobar
.
Delete Metadata
From the Portal:
To delete the metadata associated with an object, you need to edit the object:
- Click on STORAGE in the main navigation.
- Select your bucket.
- Click on on the pencil icon of the object to edit.
- Click on on the Metadata tab.
Then, for each key-value pair, you can click on the X icon to delete.
From the CLI:
We assume for this example that you are using aws s3 cli and the aws s3api
command.
The --metadata-directive REPLACE
option replaces the metadata. The --metadata-directive COPY
option first copies the the metadata, merging the original data with the supplied values onto the new object.
You can then:
$ aws s3api copy-object --copy-source <bucket>/<object> --bucket <bucket> --key <key> --metadata-directive=REPLACE