Jump to Content

Class PutObjectTaggingCommandProtected

Sets the supplied tag-set to an object that already exists in a bucket.

A tag is a key-value pair. You can associate tags with an object by sending a PUT request against the tagging subresource that is associated with the object. You can retrieve tags by sending a GET request. For more information, see GetObjectTagging.

For tagging-related restrictions related to characters and encodings, see Tag Restrictions. Note that Amazon S3 limits the maximum number of tags to 10 tags per object.

To use this operation, you must have permission to perform the s3:PutObjectTagging action. By default, the bucket owner has this permission and can grant this permission to others.

To put tags of any other version, use the versionId query parameter. You also need permission for the s3:PutObjectVersionTagging action.

For information about the Amazon S3 object tagging feature, see Object Tagging.

Special Errors

    • Code: InvalidTagError

    • Cause: The tag provided was not a valid tag. This error can occur if the tag did not pass input validation. For more information, see Object Tagging.

    • Code: MalformedXMLError

    • Cause: The XML provided does not match the schema.

    • Code: OperationAbortedError

    • Cause: A conflicting conditional action is currently in progress against this resource. Please try again.

    • Code: InternalError

    • Cause: The service was unable to apply the provided tag to the object.

Related Resources

Example

Use a bare-bones client and the command you need to make an API call.

import { S3Client, PutObjectTaggingCommand } from "@aws-sdk/client-s3"; // ES Modules import
// const { S3Client, PutObjectTaggingCommand } = require("@aws-sdk/client-s3"); // CommonJS import
const client = new S3Client(config);
const command = new PutObjectTaggingCommand(input);
const response = await client.send(command);

See

Example

To add tags to an existing object

// The following example adds tags to an existing object.
const input = {
"Bucket": "examplebucket",
"Key": "HappyFace.jpg",
"Tagging": {
"TagSet": [
{
"Key": "Key3",
"Value": "Value3"
},
{
"Key": "Key4",
"Value": "Value4"
}
]
}
};
const command = new PutObjectTaggingCommand(input);
const response = await client.send(command);
/* response ==
{
"VersionId": "null"
}
*/
// example id: to-add-tags-to-an-existing-object-1481764668793

Hierarchy

Constructors

Properties

Methods