Skip to content

put_object_tagging async

put_object_tagging(
    bucket: BucketName,
    key: ObjectKey,
    tagging: Tagging,
    *,
    config_overrides: Optional[AsyncS3ClientConfig] = None,
    version_id: Optional[ObjectVersionId] = None,
    content_md5: Optional[ContentMD5] = None,
    checksum_algorithm: Optional[ChecksumAlgorithm] = None,
    expected_bucket_owner: Optional[AccountId] = None,
    request_payer: Optional[RequestPayer] = None,
) -> PutObjectTaggingOutput

This operation is not supported for directory buckets.

Sets the supplied tag-set to an object that already exists in a bucket. A tag is a key-value pair. For more information, see Object Tagging.

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.

PutObjectTagging has the following special errors. For more Amazon S3 errors see, Error Responses.

  • InvalidTag - 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.

  • MalformedXML - The XML provided does not match the schema.

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

  • InternalError - The service was unable to apply the provided tag to the object.

The following operations are related to PutObjectTagging:

You must URL encode any signed header values that contain spaces. For example, if your header value is my file.txt, containing two spaces after my, you must URL encode this value to my%20%20file.txt.

Parameters:

  • bucket (BucketName) –

    The bucket name containing the object.

    Access points - When you use this action with an access point for general purpose buckets, you must provide the alias of the access point in place of the bucket name or specify the access point ARN. When you use this action with an access point for directory buckets, you must provide the access point name in place of the bucket name. When using the access point ARN, you must direct requests to the access point hostname. The access point hostname takes the form AccessPointName-AccountId.s3-accesspoint.Region.amazonaws.com. When using this action with an access point through the Amazon Web Services SDKs, you provide the access point ARN in place of the bucket name. For more information about access point ARNs, see Using access points in the Amazon S3 User Guide.

    S3 on Outposts - When you use this action with S3 on Outposts, you must direct requests to the S3 on Outposts hostname. The S3 on Outposts hostname takes the form AccessPointName-AccountId.outpostID.s3-outposts.Region.amazonaws.com. When you use this action with S3 on Outposts, the destination bucket must be the Outposts access point ARN or the access point alias. For more information about S3 on Outposts, see What is S3 on Outposts? in the Amazon S3 User Guide.

  • key (ObjectKey) –

    Name of the object key.

  • version_id (Optional[ObjectVersionId], default: None ) –

    The versionId of the object that the tag-set will be added to.

  • content_md5 (Optional[ContentMD5], default: None ) –

    The MD5 hash for the request body.

    For requests made using the Amazon Web Services Command Line Interface (CLI) or Amazon Web Services SDKs, this field is calculated automatically.

  • checksum_algorithm (Optional[ChecksumAlgorithm], default: None ) –

    Indicates the algorithm used to create the checksum for the object when you use the SDK. This header will not provide any additional functionality if you don't use the SDK. When you send this header, there must be a corresponding x-amz-checksum or x-amz-trailer header sent. Otherwise, Amazon S3 fails the request with the HTTP status code 400 Bad Request. For more information, see Checking object integrity in the Amazon S3 User Guide.

    If you provide an individual checksum, Amazon S3 ignores any provided ChecksumAlgorithm parameter.

  • tagging (Tagging) –

    Container for the TagSet and Tag elements

  • expected_bucket_owner (Optional[AccountId], default: None ) –

    The account ID of the expected bucket owner. If the account ID that you provide does not match the actual owner of the bucket, the request fails with the HTTP status code 403 Forbidden (access denied).

  • request_payer (Optional[RequestPayer], default: None ) –

    Confirms that the requester knows that she or he will be charged for the tagging object request. Bucket owners need not specify this parameter in their requests.

Raises:

Examples:

To add tags to an existing object The following example adds tags to an existing object.

>>> await client.put_object_tagging(bucket='examplebucket', key='HappyFace.jpg', tagging={'TagSet': [{'Key': 'Key3', 'Value': 'Value3'}, {'Key': 'Key4', 'Value': 'Value4'}]})
Source code in docs_src/capo_s3/_services/async_s3.py
async def put_object_tagging(
    self,
    bucket: "capo_s3.types.bucket_name.BucketName",
    key: "capo_s3.types.object_key.ObjectKey",
    tagging: "capo_s3.types.tagging.Tagging",
    *,
    config_overrides: Optional[AsyncS3ClientConfig] = None,
    version_id: Optional["capo_s3.types.object_version_id.ObjectVersionId"] = None,
    content_md5: Optional["capo_s3.types.content_md5.ContentMD5"] = None,
    checksum_algorithm: Optional[
        "capo_s3.types.checksum_algorithm.ChecksumAlgorithm"
    ] = None,
    expected_bucket_owner: Optional["capo_s3.types.account_id.AccountId"] = None,
    request_payer: Optional["capo_s3.types.request_payer.RequestPayer"] = None,
) -> "capo_s3.types.put_object_tagging_output.PutObjectTaggingOutput":
    """<note> <p>This operation is not supported for directory buckets.</p> </note> <p>Sets the supplied tag-set to an object that already exists in a bucket. A tag is a key-value pair. For more information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-tagging.html">Object Tagging</a>.</p> <p>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 <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectTagging.html">GetObjectTagging</a>.</p> <p>For tagging-related restrictions related to characters and encodings, see <a href="https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/allocation-tag-restrictions.html">Tag Restrictions</a>. Note that Amazon S3 limits the maximum number of tags to 10 tags per object.</p> <p>To use this operation, you must have permission to perform the <code>s3:PutObjectTagging</code> action. By default, the bucket owner has this permission and can grant this permission to others.</p> <p>To put tags of any other version, use the <code>versionId</code> query parameter. You also need permission for the <code>s3:PutObjectVersionTagging</code> action.</p> <p> <code>PutObjectTagging</code> has the following special errors. For more Amazon S3 errors see, <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/ErrorResponses.html">Error Responses</a>.</p> <ul> <li> <p> <code>InvalidTag</code> - The tag provided was not a valid tag. This error can occur if the tag did not pass input validation. For more information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/object-tagging.html">Object Tagging</a>.</p> </li> <li> <p> <code>MalformedXML</code> - The XML provided does not match the schema.</p> </li> <li> <p> <code>OperationAborted</code> - A conflicting conditional action is currently in progress against this resource. Please try again.</p> </li> <li> <p> <code>InternalError</code> - The service was unable to apply the provided tag to the object.</p> </li> </ul> <p>The following operations are related to <code>PutObjectTagging</code>:</p> <ul> <li> <p> <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObjectTagging.html">GetObjectTagging</a> </p> </li> <li> <p> <a href="https://docs.aws.amazon.com/AmazonS3/latest/API/API_DeleteObjectTagging.html">DeleteObjectTagging</a> </p> </li> </ul> <important> <p>You must URL encode any signed header values that contain spaces. For example, if your header value is <code>my file.txt</code>, containing two spaces after <code>my</code>, you must URL encode this value to <code>my%20%20file.txt</code>.</p> </important>

    Args:
        bucket: <p>The bucket name containing the object. </p> <p> <b>Access points</b> - When you use this action with an access point for general purpose buckets, you must provide the alias of the access point in place of the bucket name or specify the access point ARN. When you use this action with an access point for directory buckets, you must provide the access point name in place of the bucket name. When using the access point ARN, you must direct requests to the access point hostname. The access point hostname takes the form <i>AccessPointName</i>-<i>AccountId</i>.s3-accesspoint.<i>Region</i>.amazonaws.com. When using this action with an access point through the Amazon Web Services SDKs, you provide the access point ARN in place of the bucket name. For more information about access point ARNs, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-access-points.html">Using access points</a> in the <i>Amazon S3 User Guide</i>.</p> <p> <b>S3 on Outposts</b> - When you use this action with S3 on Outposts, you must direct requests to the S3 on Outposts hostname. The S3 on Outposts hostname takes the form <code> <i>AccessPointName</i>-<i>AccountId</i>.<i>outpostID</i>.s3-outposts.<i>Region</i>.amazonaws.com</code>. When you use this action with S3 on Outposts, the destination bucket must be the Outposts access point ARN or the access point alias. For more information about S3 on Outposts, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/S3onOutposts.html">What is S3 on Outposts?</a> in the <i>Amazon S3 User Guide</i>.</p>
        key: <p>Name of the object key.</p>
        version_id: <p>The versionId of the object that the tag-set will be added to.</p>
        content_md5: <p>The MD5 hash for the request body.</p> <p>For requests made using the Amazon Web Services Command Line Interface (CLI) or Amazon Web Services SDKs, this field is calculated automatically.</p>
        checksum_algorithm: <p>Indicates the algorithm used to create the checksum for the object when you use the SDK. This header will not provide any additional functionality if you don't use the SDK. When you send this header, there must be a corresponding <code>x-amz-checksum</code> or <code>x-amz-trailer</code> header sent. Otherwise, Amazon S3 fails the request with the HTTP status code <code>400 Bad Request</code>. For more information, see <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html">Checking object integrity</a> in the <i>Amazon S3 User Guide</i>.</p> <p>If you provide an individual checksum, Amazon S3 ignores any provided <code>ChecksumAlgorithm</code> parameter.</p>
        tagging: <p>Container for the <code>TagSet</code> and <code>Tag</code> elements</p>
        expected_bucket_owner: <p>The account ID of the expected bucket owner. If the account ID that you provide does not match the actual owner of the bucket, the request fails with the HTTP status code <code>403 Forbidden</code> (access denied).</p>
        request_payer: <p>Confirms that the requester knows that she or he will be charged for the tagging object request. Bucket owners need not specify this parameter in their requests.</p>

    Raises:
        capo_s3.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To add tags to an existing object
        The following example adds tags to an existing object.

        >>> await client.put_object_tagging(bucket='examplebucket', key='HappyFace.jpg', tagging={'TagSet': [{'Key': 'Key3', 'Value': 'Value3'}, {'Key': 'Key4', 'Value': 'Value4'}]})
    """

    async def _handler(
        req: "AsyncOperationRequest[capo_s3.types.put_object_tagging_request.PutObjectTaggingRequest]",
    ) -> AsyncOperationResponse[
        "capo_s3.types.put_object_tagging_output.PutObjectTaggingOutput"
    ]:
        import capo_s3._operations.amazon_s3.put_object_tagging

        (
            output,
            http_response,
        ) = await capo_s3._operations.amazon_s3.put_object_tagging.async_put_object_tagging(
            req.options, req.input
        )
        return AsyncOperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("PutObjectTagging")
    )
    input_: capo_s3.types.put_object_tagging_request.PutObjectTaggingRequest = {
        "bucket": bucket,
        "key": key,
        "tagging": tagging,
    }
    if version_id is not None:
        input_["version_id"] = version_id
    if content_md5 is not None:
        input_["content_md5"] = content_md5
    if checksum_algorithm is not None:
        input_["checksum_algorithm"] = checksum_algorithm
    if expected_bucket_owner is not None:
        input_["expected_bucket_owner"] = expected_bucket_owner
    if request_payer is not None:
        input_["request_payer"] = request_payer

    response = await aexecute_pipeline(
        AsyncOperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    await response.response.aclose()
    return response.output