Skip to content

tag_resource

tag_resource(
    resource_arn: Arn,
    tags: Tags,
    *,
    config_overrides: Optional[forecastClientConfig] = None,
) -> TagResourceResponse

Associates the specified tags to a resource with the specified resourceArn. If existing tags on a resource are not specified in the request parameters, they are not changed. When a resource is deleted, the tags associated with that resource are also deleted.

Parameters:

  • resource_arn (Arn) –

    The Amazon Resource Name (ARN) that identifies the resource for which to list the tags.

  • tags (Tags) –

    The tags to add to the resource. A tag is an array of key-value pairs.

    The following basic restrictions apply to tags:

    • Maximum number of tags per resource - 50.

    • For each resource, each tag key must be unique, and each tag key can have only one value.

    • Maximum key length - 128 Unicode characters in UTF-8.

    • Maximum value length - 256 Unicode characters in UTF-8.

    • If your tagging schema is used across multiple services and resources, remember that other services may have restrictions on allowed characters. Generally allowed characters are: letters, numbers, and spaces representable in UTF-8, and the following characters: + - = . _ : / @.

    • Tag keys and values are case sensitive.

    • Do not use aws:, AWS:, or any upper or lowercase combination of such as a prefix for keys as it is reserved for Amazon Web Services use. You cannot edit or delete tag keys with this prefix. Values can have this prefix. If a tag value has aws as its prefix but the key does not, then Forecast considers it to be a user tag and will count against the limit of 50 tags. Tags with only the key prefix of aws do not count against your tags per resource limit.

Raises:

  • InvalidInputException –

    We can't process the request because it includes an invalid value or a value that exceeds the valid range.

  • LimitExceededException –

    The limit on the number of resources per account has been exceeded.

  • ResourceNotFoundException –

    We can't find a resource with that Amazon Resource Name (ARN). Check the ARN and try again.

  • UnknownServiceError –

    The service returned an error code this client does not model.

Source code in docs_src/capo_forecast/_services/forecast.py
def tag_resource(
    self,
    resource_arn: "capo_forecast.types.arn.Arn",
    tags: "capo_forecast.types.tags.Tags",
    *,
    config_overrides: Optional[forecastClientConfig] = None,
) -> "capo_forecast.types.tag_resource_response.TagResourceResponse":
    """<p>Associates the specified tags to a resource with the specified <code>resourceArn</code>. If existing tags on a resource are not specified in the request parameters, they are not changed. When a resource is deleted, the tags associated with that resource are also deleted.</p>

    Args:
        resource_arn: <p>The Amazon Resource Name (ARN) that identifies the resource for which to list the tags. </p>
        tags: <p>The tags to add to the resource. A tag is an array of key-value pairs.</p> <p>The following basic restrictions apply to tags:</p> <ul> <li> <p>Maximum number of tags per resource - 50.</p> </li> <li> <p>For each resource, each tag key must be unique, and each tag key can have only one value.</p> </li> <li> <p>Maximum key length - 128 Unicode characters in UTF-8.</p> </li> <li> <p>Maximum value length - 256 Unicode characters in UTF-8.</p> </li> <li> <p>If your tagging schema is used across multiple services and resources, remember that other services may have restrictions on allowed characters. Generally allowed characters are: letters, numbers, and spaces representable in UTF-8, and the following characters: + - = . _ : / @.</p> </li> <li> <p>Tag keys and values are case sensitive.</p> </li> <li> <p>Do not use <code>aws:</code>, <code>AWS:</code>, or any upper or lowercase combination of such as a prefix for keys as it is reserved for Amazon Web Services use. You cannot edit or delete tag keys with this prefix. Values can have this prefix. If a tag value has <code>aws</code> as its prefix but the key does not, then Forecast considers it to be a user tag and will count against the limit of 50 tags. Tags with only the key prefix of <code>aws</code> do not count against your tags per resource limit.</p> </li> </ul>

    Raises:
        capo_forecast.errors.invalid_input_exception.InvalidInputException: <p>We can't process the request because it includes an invalid value or a value that exceeds the valid range.</p>
        capo_forecast.errors.limit_exceeded_exception.LimitExceededException: <p>The limit on the number of resources per account has been exceeded.</p>
        capo_forecast.errors.resource_not_found_exception.ResourceNotFoundException: <p>We can't find a resource with that Amazon Resource Name (ARN). Check the ARN and try again.</p>
        capo_forecast.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

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

        output, http_response = (
            capo_forecast._operations.amazon_forecast.tag_resource.tag_resource(
                req.options, req.input
            )
        )
        return OperationResponse(output=output, response=http_response)

    def _redact_input(
        input_: "capo_forecast.types.tag_resource_request.TagResourceRequest",
    ) -> dict[str, Any]:
        import capo_forecast.types.tag_resource_request

        return capo_forecast.types.tag_resource_request.redact_sensitive(input_)

    interceptors_, options_ = self.operation_options(
        config_overrides,
        OperationLogging("TagResource", redact_input=_redact_input),
    )
    input_: capo_forecast.types.tag_resource_request.TagResourceRequest = {
        "resource_arn": resource_arn,
        "tags": tags,
    }

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