Skip to content

tag_resource

tag_resource(
    resource_arn: Arn,
    resource_tags: ResourceTagList,
    *,
    config_overrides: Optional[CostExplorerClientConfig] = None,
) -> TagResourceResponse

An API operation for adding one or more tags (key-value pairs) to a resource.

You can use the TagResource operation with a resource that already has tags. If you specify a new tag key for the resource, this tag is appended to the list of tags associated with the resource. If you specify a tag key that is already associated with the resource, the new tag value you specify replaces the previous value for that tag.

Although the maximum number of array members is 200, user-tag maximum is 50. The remaining are reserved for Amazon Web Services use.

Parameters:

  • resource_arn (Arn) –

    The Amazon Resource Name (ARN) of the resource. For a list of supported resources, see ResourceTag.

  • resource_tags (ResourceTagList) –

    A list of tag key-value pairs to be added to the resource.

    Each tag consists of a key and a value, and each key must be unique for the resource. The following restrictions apply to resource tags:

    • Although the maximum number of array members is 200, you can assign a maximum of 50 user-tags to one resource. The remaining are reserved for Amazon Web Services use

    • The maximum length of a key is 128 characters

    • The maximum length of a value is 256 characters

    • Keys and values can only contain alphanumeric characters, spaces, and any of the following: _.:/=+@-

    • Keys and values are case sensitive

    • Keys and values are trimmed for any leading or trailing whitespaces

    • Don’t use aws: as a prefix for your keys. This prefix is reserved for Amazon Web Services use

Raises:

Source code in docs_src/capo_cost_explorer/_services/cost_explorer.py
def tag_resource(
    self,
    resource_arn: "capo_cost_explorer.types.arn.Arn",
    resource_tags: "capo_cost_explorer.types.resource_tag_list.ResourceTagList",
    *,
    config_overrides: Optional[CostExplorerClientConfig] = None,
) -> "capo_cost_explorer.types.tag_resource_response.TagResourceResponse":
    """<p>An API operation for adding one or more tags (key-value pairs) to a resource.</p> <p>You can use the <code>TagResource</code> operation with a resource that already has tags. If you specify a new tag key for the resource, this tag is appended to the list of tags associated with the resource. If you specify a tag key that is already associated with the resource, the new tag value you specify replaces the previous value for that tag.</p> <p>Although the maximum number of array members is 200, user-tag maximum is 50. The remaining are reserved for Amazon Web Services use.</p>

    Args:
        resource_arn: <p>The Amazon Resource Name (ARN) of the resource. For a list of supported resources, see <a href="https://docs.aws.amazon.com/aws-cost-management/latest/APIReference/API_ResourceTag.html">ResourceTag</a>. </p>
        resource_tags: <p> A list of tag key-value pairs to be added to the resource.</p> <p>Each tag consists of a key and a value, and each key must be unique for the resource. The following restrictions apply to resource tags:</p> <ul> <li> <p>Although the maximum number of array members is 200, you can assign a maximum of 50 user-tags to one resource. The remaining are reserved for Amazon Web Services use</p> </li> <li> <p>The maximum length of a key is 128 characters</p> </li> <li> <p>The maximum length of a value is 256 characters</p> </li> <li> <p>Keys and values can only contain alphanumeric characters, spaces, and any of the following: <code>_.:/=+@-</code> </p> </li> <li> <p>Keys and values are case sensitive</p> </li> <li> <p>Keys and values are trimmed for any leading or trailing whitespaces</p> </li> <li> <p>Don’t use <code>aws:</code> as a prefix for your keys. This prefix is reserved for Amazon Web Services use</p> </li> </ul>

    Raises:
        capo_cost_explorer.errors.limit_exceeded_exception.LimitExceededException: <p>You made too many calls in a short period of time. Try again later.</p>
        capo_cost_explorer.errors.resource_not_found_exception.ResourceNotFoundException: <p> The specified ARN in the request doesn't exist. </p>
        capo_cost_explorer.errors.too_many_tags_exception.TooManyTagsException: <p>Can occur if you specify a number of tags for a resource greater than the maximum 50 user tags per resource.</p>
        capo_cost_explorer.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_cost_explorer.types.tag_resource_request.TagResourceRequest]",
    ) -> OperationResponse[
        "capo_cost_explorer.types.tag_resource_response.TagResourceResponse"
    ]:
        import capo_cost_explorer._operations.aws_insights_index_service.tag_resource

        output, http_response = (
            capo_cost_explorer._operations.aws_insights_index_service.tag_resource.tag_resource(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    interceptors_, options_ = self.operation_options(
        config_overrides, OperationLogging("TagResource")
    )
    input_: capo_cost_explorer.types.tag_resource_request.TagResourceRequest = {
        "resource_arn": resource_arn,
        "resource_tags": resource_tags,
    }

    response = execute_pipeline(
        OperationRequest(input=input_, options=options_),
        handler=_handler,
        interceptors=list(interceptors_),
    )
    response.response.close()
    return response.output