How to Add Tags and Metadata to S3 Files with AWS Emulator
Tags and user-defined metadata are two ways to attach information to an S3 object (file) for classifying it or recording the owner and processing status. You can set either one when you upload the file, but the ways to change them afterward differ. Tags are replaced in place with put-object-tagging, while metadata is replaced by copying the file onto itself. I checked this difference, and a pitfall where the Content-Type changes to binary/octet-stream when you replace metadata, against AWS Emulator without using an AWS account. The commands and output are included as they are.
The test environment was Ubuntu 24.04 (x86_64), AWS Emulator 1.0.602 (released November 24, 2026), and AWS CLI 2.42.2. I did not use an AWS account or credentials. I did not test the behavior on real S3, pricing, S3 annotations, access permissions that depend on tags (bucket policies and IAM policies), or how tags are set on a bucket with versioning enabled. Where this article describes real S3, it relies on the official documentation. According to the AWS Emulator official documentation, AWS checks the emulator's behavior against the real service only in the US West (Oregon, us-west-2) Region (global services use us-east-1). The us-east-1 S3 used in this article is outside that scope.
- 1. The difference between tags and metadata
- 2. Start the emulator and create a bucket
- 3. Set tags and metadata when uploading
- 4. Read back what was set
- 5. Changing tags: the tags you send replace the whole set
- 6. Changing metadata: replace it by copying the object onto itself
- 7. Tags and metadata when copying to a different key
- 8. Settings that get rejected
- 9. Neither appears in the file listing
The difference between tags and metadata
The metadata page in the S3 User Guide describes both as key-value pairs. Summarizing the differences from the official documentation and the results I confirmed in this article:
| Tags | User-defined metadata | |
|---|---|---|
| Limits on count and size | Up to 10 per file. Keys up to 128 characters, values up to 256 characters | Up to 2 KB in total |
| Changing afterward | Replace with put-object-tagging |
Replace by copying the file onto itself |
| HTTP headers on download | Only the count (x-amz-tagging-count) |
All of them, in headers starting with x-amz-meta- |
The tag limits are described on the object tagging page. The same page says tags can also be used in conditions for access permissions and lifecycle rules, and for filtering S3 analytics and CloudWatch metrics. The 2 KB limit on metadata and the fact that the only way to change it is by copying are described on the metadata page mentioned above.
Start the emulator and create a bucket
AWS Emulator is an emulator that accepts AWS API calls locally. According to the official documentation, you do not need an AWS account, and requests are not sent to AWS. How to install it and the environment variables that point the AWS CLI at the emulator are covered in the separate articles "How to install AWS Emulator on Ubuntu and start using it" and "How to store and retrieve files in S3 with AWS Emulator." In this article, I set the environment variables from the official documentation in the shell and sent commands to the emulator started with aws-emulator -t off. -t off turns off the usage data (the telemetry) that the emulator sends to AWS by default.
If the connection works, the user name in the ARN from aws sts get-caller-identity is emulator (the 12-digit account ID is replaced). I also prepare a bucket and a CSV file to upload.
$ aws sts get-caller-identity --query Arn --output text
arn:aws:iam::<12桁のアカウントID>:user/emulator
$ aws s3 mb s3://example-bucket
make_bucket: example-bucket
$ printf "month,total\n2026-11,42\n" > report.csv; cat report.csv
month,total
2026-11,42
Set tags and metadata when uploading
With aws s3api put-object, you pass metadata to --metadata as key=value pairs joined by commas. You pass tags to --tagging as key=value pairs joined by &. Tags are written in URL query form because the x-amz-tagging header is defined that way in the metadata page's table. Here I deliberately started the metadata keys with uppercase letters.
$ aws s3api put-object --bucket example-bucket --key reports/2026-11.csv --body report.csv --content-type text/csv --metadata Owner=tama,Project=demo --tagging "project=demo&status=draft"
{
"ETag": "\"207814e620a5bf24e6901319d524573c\"",
"ChecksumCRC64NVME": "stXcN9mYgUI=",
"ChecksumType": "FULL_OBJECT",
"ServerSideEncryption": "AES256"
}
Read back what was set
You can read metadata with head-object. The keys came back in lowercase, such as owner and project. The metadata page also states that S3 stores user-defined metadata keys in lowercase. The contents of tags are not shown; only the count appears in TagCount.
$ aws s3api head-object --bucket example-bucket --key reports/2026-11.csv
{
"AcceptRanges": "bytes",
"LastModified": "2026-11-24T13:39:59+00:00",
"ContentLength": 23,
"ETag": "\"207814e620a5bf24e6901319d524573c\"",
"ContentType": "text/csv",
"ServerSideEncryption": "AES256",
"Metadata": {
"owner": "tama",
"project": "demo"
},
"TagCount": 2
}
You read the contents of tags with get-object-tagging.
$ aws s3api get-object-tagging --bucket example-bucket --key reports/2026-11.csv
{
"TagSet": [
{
"Key": "project",
"Value": "demo"
},
{
"Key": "status",
"Value": "draft"
}
]
}
I also checked how this looks to someone downloading the file. I sent a GET with curl to a presigned URL created by aws s3 presign, and used grep to pull out only the relevant lines from the HTTP headers in the response. Metadata appeared in full as headers such as x-amz-meta-owner, while tags showed only their count in x-amz-tagging-count.
$ U=$(aws s3 presign s3://example-bucket/reports/2026-11.csv); curl -s -D - -o /dev/null --cacert ~/.aws/emulator/9297/ca.pem "$U" | grep -i -E "^(HTTP|content-type|last-modified|x-amz-meta|x-amz-tagging)"
HTTP/1.1 200 OK
content-type: text/csv
last-modified: Tue, 24 Nov 2026 13:39:59 GMT
x-amz-meta-owner: tama
x-amz-meta-project: demo
x-amz-tagging-count: 2
According to the GetObject API reference, x-amz-tagging-count is also the tag count on real S3, and it is returned when the caller has permission to read tags. For metadata, the metadata page says that when retrieved through the REST API, it is returned as headers with the x-amz-meta- prefix.
Changing tags: the tags you send replace the whole set
put-object-tagging replaces the entire set with the tags you send. When I sent only status=final, the existing project=demo was removed.
$ aws s3api put-object-tagging --bucket example-bucket --key reports/2026-11.csv --tagging "TagSet=[{Key=status,Value=final}]"
$ aws s3api get-object-tagging --bucket example-bucket --key reports/2026-11.csv
{
"TagSet": [
{
"Key": "status",
"Value": "final"
}
]
}
Changing tags does not change the file itself. LastModified and ETag stayed as they were when the file was uploaded, and only TagCount changed to 1.
$ aws s3api head-object --bucket example-bucket --key reports/2026-11.csv --query "[LastModified,ETag,TagCount]"
[
"2026-11-24T13:39:59+00:00",
"\"207814e620a5bf24e6901319d524573c\"",
1
]
To add one tag, read the current tags, add the new one, and then set them all together. The object tagging page also describes this procedure: get the current tags, change them locally, and replace the set. Here I added the tag with jq.
$ aws s3api get-object-tagging --bucket example-bucket --key reports/2026-11.csv --query TagSet > tags.json; cat tags.json
[
{
"Key": "status",
"Value": "final"
}
]
$ jq -c "{TagSet: (. + [{Key:\"project\",Value:\"demo\"}])}" tags.json > new-tags.json; cat new-tags.json
{"TagSet":[{"Key":"status","Value":"final"},{"Key":"project","Value":"demo"}]}
$ aws s3api put-object-tagging --bucket example-bucket --key reports/2026-11.csv --tagging file://new-tags.json
$ aws s3api get-object-tagging --bucket example-bucket --key reports/2026-11.csv --output text
TAGSET status final
TAGSET project demo
To remove all tags, use delete-object-tagging. After that, TagSet was empty.
$ aws s3api delete-object-tagging --bucket example-bucket --key reports/2026-11.csv
$ aws s3api get-object-tagging --bucket example-bucket --key reports/2026-11.csv
{
"TagSet": []
}
For the steps that follow, I set the single status=final tag again.
$ aws s3api put-object-tagging --bucket example-bucket --key reports/2026-11.csv --tagging "TagSet=[{Key=status,Value=final}]"
Changing metadata: replace it by copying the object onto itself
There is no command for metadata that corresponds to put-object-tagging for tags. You use copy-object to copy the object onto itself, with the same bucket and key, to replace the metadata. However, a copy that specifies only --metadata was rejected.
$ aws s3api copy-object --bucket example-bucket --key reports/2026-11.csv --copy-source example-bucket/reports/2026-11.csv --metadata owner=mike
aws: [ERROR]: An error occurred (InvalidRequest) when calling the CopyObject operation: This copy request is illegal because it is trying to copy an object to itself without changing the object's metadata, storage class, website redirect location or encryption attributes.
According to the CopyObject API reference, when x-amz-metadata-directive is not specified, the default is COPY, which carries over the original metadata unchanged. The emulator rejected this copy, which passed only --metadata, as a copy that changes nothing. To replace the metadata, add --metadata-directive REPLACE.
$ aws s3api copy-object --bucket example-bucket --key reports/2026-11.csv --copy-source example-bucket/reports/2026-11.csv --metadata owner=mike --metadata-directive REPLACE
{
"ServerSideEncryption": "AES256",
"CopyObjectResult": {
"ETag": "\"207814e620a5bf24e6901319d524573c\"",
"LastModified": "2026-11-24T13:40:14+00:00",
"ChecksumType": "FULL_OBJECT",
"ChecksumCRC64NVME": "stXcN9mYgUI="
}
}
In head-object, the metadata was replaced with only owner=mike. The content did not change, so ETag stayed the same, but LastModified changed to the time of the copy. The tag status=final was kept.
However, ContentType changed from text/csv to binary/octet-stream.
$ aws s3api head-object --bucket example-bucket --key reports/2026-11.csv --query "{LastModified:LastModified,ETag:ETag,ContentType:ContentType,Metadata:Metadata,TagCount:TagCount}"
{
"LastModified": "2026-11-24T13:40:14+00:00",
"ETag": "\"207814e620a5bf24e6901319d524573c\"",
"ContentType": "binary/octet-stream",
"Metadata": {
"owner": "mike"
},
"TagCount": 1
}
$ aws s3api get-object-tagging --bucket example-bucket --key reports/2026-11.csv --output text
TAGSET status final
When copying with --metadata-directive REPLACE, specify again every Content-Type and metadata value you want to keep. Even if you only meant to replace the user-defined metadata, in this test environment the Content-Type I did not specify was not kept.
When I copied again with the Content-Type and all the metadata I wanted to keep listed, it was restored.
$ aws s3api copy-object --bucket example-bucket --key reports/2026-11.csv --copy-source example-bucket/reports/2026-11.csv --metadata-directive REPLACE --content-type text/csv --metadata owner=mike,project=demo --query CopyObjectResult.ETag
"\"207814e620a5bf24e6901319d524573c\""
$ aws s3api head-object --bucket example-bucket --key reports/2026-11.csv --query "{ContentType:ContentType,Metadata:Metadata,TagCount:TagCount}"
{
"ContentType": "text/csv",
"Metadata": {
"owner": "mike",
"project": "demo"
},
"TagCount": 1
}
Tags and metadata when copying to a different key
When copying to a different key without specifying anything else, the Content-Type, metadata, and tags were all carried over unchanged.
$ aws s3api copy-object --bucket example-bucket --key archive/2026-11.csv --copy-source example-bucket/reports/2026-11.csv --query CopyObjectResult.ETag
"\"207814e620a5bf24e6901319d524573c\""
$ aws s3api head-object --bucket example-bucket --key archive/2026-11.csv --query "{ContentType:ContentType,Metadata:Metadata}"
{
"ContentType": "text/csv",
"Metadata": {
"owner": "mike",
"project": "demo"
}
}
$ aws s3api get-object-tagging --bucket example-bucket --key archive/2026-11.csv --output text
TAGSET status final
To give the copy different tags, add --tagging-directive REPLACE together with --tagging. The CopyObject API reference also says the default for tags is COPY, and that with REPLACE the tags in x-amz-tagging are used.
$ aws s3api copy-object --bucket example-bucket --key archive/2026-11-b.csv --copy-source example-bucket/reports/2026-11.csv --tagging-directive REPLACE --tagging "status=archived" --query CopyObjectResult.ETag
"\"207814e620a5bf24e6901319d524573c\""
$ aws s3api get-object-tagging --bucket example-bucket --key archive/2026-11-b.csv --output text
TAGSET status archived
Settings that get rejected
The emulator rejected tags and metadata that exceed the limits, and tags that repeat the same key. Setting 11 tags returned BadRequest, and two tags with the same key returned InvalidTag.
$ aws s3api put-object-tagging --bucket example-bucket --key reports/2026-11.csv --tagging "TagSet=[$(for i in $(seq 1 11); do printf "{Key=k$i,Value=v},"; done | sed "s/,$//")]"
aws: [ERROR]: An error occurred (BadRequest) when calling the PutObjectTagging operation: Object tags cannot be greater than 10
$ aws s3api put-object-tagging --bucket example-bucket --key reports/2026-11.csv --tagging "TagSet=[{Key=status,Value=a},{Key=status,Value=b}]"
aws: [ERROR]: An error occurred (InvalidTag) when calling the PutObjectTagging operation: Cannot provide multiple Tags with the same key
A tag with a 129-character key was rejected with InvalidTag, and metadata with a 2,100-character value was rejected with MetadataTooLarge.
$ aws s3api put-object-tagging --bucket example-bucket --key reports/2026-11.csv --tagging "TagSet=[{Key=$(printf "k%.0s" $(seq 1 129)),Value=v}]"
aws: [ERROR]: An error occurred (InvalidTag) when calling the PutObjectTagging operation: The TagKey you have provided is invalid
$ aws s3api put-object --bucket example-bucket --key big-meta.csv --body report.csv --metadata "note=$(printf "a%.0s" $(seq 1 2100))"
aws: [ERROR]: An error occurred (MetadataTooLarge) when calling the PutObject operation: Your metadata headers exceed the maximum allowed metadata size
Non-ASCII text was handled differently for metadata and tags. When I put the Japanese value "neko no te" (meaning "a cat's paw") in a metadata value, it failed with a ParamValidation error. The error message does not include "when calling the … operation," and it is a ParamValidation error, which shows that this is not a response from the emulator. The AWS CLI blocked the non-ASCII characters before sending the request. The same value, "neko no te," put in a tag value was stored as is and could be read back.
$ aws s3api put-object --bucket example-bucket --key jp-meta.csv --body report.csv --metadata "team=猫の手"
aws: [ERROR]: An error occurred (ParamValidation): Parameter validation failed:
Non ascii characters found in S3 metadata for key "team", value: "猫の手".
S3 metadata can only contain ASCII characters.
$ aws s3api put-object-tagging --bucket example-bucket --key reports/2026-11.csv --tagging "TagSet=[{Key=team,Value=猫の手}]"
$ aws s3api get-object-tagging --bucket example-bucket --key reports/2026-11.csv --output text
TAGSET team 猫の手
According to the metadata page, S3 itself accepts Unicode characters in metadata values and returns non-ASCII characters encoded in the RFC 2047 form. It also recommends sticking to US-ASCII when sending through the REST API, to avoid display problems.
Neither appears in the file listing
Neither tags nor metadata appeared in the list-objects-v2 listing. You cannot filter files by tags or metadata from the listing results alone.
$ aws s3api list-objects-v2 --bucket example-bucket --prefix reports/
{
"Contents": [
{
"Key": "reports/2026-11.csv",
"LastModified": "2026-11-24T13:40:16+00:00",
"ETag": "\"207814e620a5bf24e6901319d524573c\"",
"ChecksumAlgorithm": [
"CRC64NVME"
],
"ChecksumType": "FULL_OBJECT",
"Size": 23,
"StorageClass": "STANDARD"
}
],
"RequestCharged": null,
"Prefix": "reports/"
}
The setting that uses tags to automatically delete old files is covered in the separate article "How to try S3 lifecycle rules with AWS Emulator."





