Skip to content

tag_resource

tag_resource(
    resource_arn: AmazonResourceName,
    tags: TagMap,
    *,
    config_overrides: Optional[ApplicationAutoScalingClientConfig] = None,
) -> TagResourceResponse

Adds or edits tags on an Application Auto Scaling scalable target.

Each tag consists of a tag key and a tag value, which are both case-sensitive strings. To add a tag, specify a new tag key and a tag value. To edit a tag, specify an existing tag key and a new tag value.

You can use this operation to tag an Application Auto Scaling scalable target, but you cannot tag a scaling policy or scheduled action.

You can also add tags to an Application Auto Scaling scalable target while creating it (RegisterScalableTarget).

For general information about tags, including the format and syntax, see Tagging your Amazon Web Services resources in the Amazon Web Services General Reference.

Use tags to control access to a scalable target. For more information, see Tagging support for Application Auto Scaling in the Application Auto Scaling User Guide.

Parameters:

  • resource_arn (AmazonResourceName) –

    Identifies the Application Auto Scaling scalable target that you want to apply tags to.

    For example: arn:aws:application-autoscaling:us-east-1:123456789012:scalable-target/1234abcd56ab78cd901ef1234567890ab123

    To get the ARN for a scalable target, use DescribeScalableTargets.

  • tags (TagMap) –

    The tags assigned to the resource. A tag is a label that you assign to an Amazon Web Services resource.

    Each tag consists of a tag key and a tag value.

    You cannot have more than one tag on an Application Auto Scaling scalable target with the same tag key. If you specify an existing tag key with a different tag value, Application Auto Scaling replaces the current tag value with the specified one.

    For information about the rules that apply to tag keys and tag values, see User-defined tag restrictions in the Amazon Web Services Billing User Guide.

Raises:

Examples:

To add a tag to a scalable target This example adds a tag with the key name "environment" and the value "production" to the scalable target specified by its ARN.

>>> client.tag_resource(resource_arn='arn:aws:application-autoscaling:us-west-2:123456789012:scalable-target/1234abcd56ab78cd901ef1234567890ab123', tags={'environment': 'production'})
Source code in docs_src/capo_application_auto_scaling/_services/application_auto_scaling.py
def tag_resource(
    self,
    resource_arn: "capo_application_auto_scaling.types.amazon_resource_name.AmazonResourceName",
    tags: "capo_application_auto_scaling.types.tag_map.TagMap",
    *,
    config_overrides: Optional[ApplicationAutoScalingClientConfig] = None,
) -> (
    "capo_application_auto_scaling.types.tag_resource_response.TagResourceResponse"
):
    """<p>Adds or edits tags on an Application Auto Scaling scalable target.</p> <p>Each tag consists of a tag key and a tag value, which are both case-sensitive strings. To add a tag, specify a new tag key and a tag value. To edit a tag, specify an existing tag key and a new tag value.</p> <p>You can use this operation to tag an Application Auto Scaling scalable target, but you cannot tag a scaling policy or scheduled action.</p> <p>You can also add tags to an Application Auto Scaling scalable target while creating it (<code>RegisterScalableTarget</code>).</p> <p>For general information about tags, including the format and syntax, see <a href="https://docs.aws.amazon.com/general/latest/gr/aws_tagging.html">Tagging your Amazon Web Services resources</a> in the <i>Amazon Web Services General Reference</i>.</p> <p>Use tags to control access to a scalable target. For more information, see <a href="https://docs.aws.amazon.com/autoscaling/application/userguide/resource-tagging-support.html">Tagging support for Application Auto Scaling</a> in the <i>Application Auto Scaling User Guide</i>.</p>

    Args:
        resource_arn: <p>Identifies the Application Auto Scaling scalable target that you want to apply tags to.</p> <p>For example: <code>arn:aws:application-autoscaling:us-east-1:123456789012:scalable-target/1234abcd56ab78cd901ef1234567890ab123</code> </p> <p>To get the ARN for a scalable target, use <a>DescribeScalableTargets</a>.</p>
        tags: <p>The tags assigned to the resource. A tag is a label that you assign to an Amazon Web Services resource.</p> <p>Each tag consists of a tag key and a tag value.</p> <p>You cannot have more than one tag on an Application Auto Scaling scalable target with the same tag key. If you specify an existing tag key with a different tag value, Application Auto Scaling replaces the current tag value with the specified one.</p> <p>For information about the rules that apply to tag keys and tag values, see <a href="https://docs.aws.amazon.com/awsaccountbilling/latest/aboutv2/allocation-tag-restrictions.html">User-defined tag restrictions</a> in the <i>Amazon Web Services Billing User Guide</i>.</p>

    Raises:
        capo_application_auto_scaling.errors.resource_not_found_exception.ResourceNotFoundException: <p>The specified resource doesn't exist.</p>
        capo_application_auto_scaling.errors.too_many_tags_exception.TooManyTagsException: <p>The request contains too many tags. Try the request again with fewer tags.</p>
        capo_application_auto_scaling.errors.validation_exception.ValidationException: <p>An exception was thrown for a validation issue. Review the available parameters for the API request.</p>
        capo_application_auto_scaling.errors.UnknownServiceError: The service returned an error code this client does not model.

    Examples:
        To add a tag to a scalable target
        This example adds a tag with the key name "environment" and the value "production" to the scalable target specified by its ARN.

        >>> client.tag_resource(resource_arn='arn:aws:application-autoscaling:us-west-2:123456789012:scalable-target/1234abcd56ab78cd901ef1234567890ab123', tags={'environment': 'production'})
    """

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

        output, http_response = (
            capo_application_auto_scaling._operations.any_scale_frontend_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_application_auto_scaling.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