Skip to content

tag_resource

tag_resource(
    *,
    config_overrides: Optional[CloudWatchClientConfig] = None,
    resource_arn: Optional[AmazonResourceName] = None,
    tags: Optional[TagList] = None,
) -> TagResourceOutput

Assigns one or more tags (key-value pairs) to the specified CloudWatch resource. Currently, the only CloudWatch resources that can be tagged are alarms, dashboards, metric streams and Contributor Insights rules.

Tags can help you organize and categorize your resources. You can also use them to scope user permissions by granting a user permission to access or change only resources with certain tag values.

Tags don't have any semantic meaning to Amazon Web Services and are interpreted strictly as strings of characters.

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

You can associate as many as 50 tags with a CloudWatch resource.

Parameters:

  • resource_arn (Optional[AmazonResourceName], default: None ) –

    The ARN of the CloudWatch resource that you're adding tags to.

    The ARN format of an alarm is arn:aws:cloudwatch:Region:account-id:alarm:alarm-name

    The ARN format of a Contributor Insights rule is arn:aws:cloudwatch:Region:account-id:insight-rule/insight-rule-name

    The ARN format of a dashboard is arn:aws:cloudwatch::account-id:dashboard/dashboard-name

    The ARN format of a metric stream is arn:aws:cloudwatch:Region:account-id:metric-stream/metric-stream-name

    For more information about ARN format, see Resource Types Defined by Amazon CloudWatch in the Amazon Web Services General Reference.

  • tags (Optional[TagList], default: None ) –

    The list of key-value pairs to associate with the alarm.

Raises:

Source code in docs_src/capo_cloudwatch/_services/cloud_watch.py
def tag_resource(
    self,
    *,
    config_overrides: Optional[CloudWatchClientConfig] = None,
    resource_arn: Optional[
        "capo_cloudwatch.types.amazon_resource_name.AmazonResourceName"
    ] = None,
    tags: Optional["capo_cloudwatch.types.tag_list.TagList"] = None,
) -> "capo_cloudwatch.types.tag_resource_output.TagResourceOutput":
    """<p>Assigns one or more tags (key-value pairs) to the specified CloudWatch resource. Currently, the only CloudWatch resources that can be tagged are alarms, dashboards, metric streams and Contributor Insights rules.</p> <p>Tags can help you organize and categorize your resources. You can also use them to scope user permissions by granting a user permission to access or change only resources with certain tag values.</p> <p>Tags don't have any semantic meaning to Amazon Web Services and are interpreted strictly as strings of characters.</p> <p>You can use the <code>TagResource</code> action with an alarm that already has tags. If you specify a new tag key for the alarm, this tag is appended to the list of tags associated with the alarm. If you specify a tag key that is already associated with the alarm, the new tag value that you specify replaces the previous value for that tag.</p> <p>You can associate as many as 50 tags with a CloudWatch resource.</p>

    Args:
        resource_arn: <p>The ARN of the CloudWatch resource that you're adding tags to.</p> <p>The ARN format of an alarm is <code>arn:aws:cloudwatch:<i>Region</i>:<i>account-id</i>:alarm:<i>alarm-name</i> </code> </p> <p>The ARN format of a Contributor Insights rule is <code>arn:aws:cloudwatch:<i>Region</i>:<i>account-id</i>:insight-rule/<i>insight-rule-name</i> </code> </p> <p>The ARN format of a dashboard is <code>arn:aws:cloudwatch::<i>account-id</i>:dashboard/<i>dashboard-name</i> </code> </p> <p>The ARN format of a metric stream is <code>arn:aws:cloudwatch:<i>Region</i>:<i>account-id</i>:metric-stream/<i>metric-stream-name</i> </code> </p> <p>For more information about ARN format, see <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/list_amazoncloudwatch.html#amazoncloudwatch-resources-for-iam-policies"> Resource Types Defined by Amazon CloudWatch</a> in the <i>Amazon Web Services General Reference</i>.</p>
        tags: <p>The list of key-value pairs to associate with the alarm.</p>

    Raises:
        capo_cloudwatch.errors.concurrent_modification_exception.ConcurrentModificationException: <p>More than one process tried to modify a resource at the same time.</p>
        capo_cloudwatch.errors.conflict_exception.ConflictException: <p>This operation attempted to create a resource that already exists.</p>
        capo_cloudwatch.errors.internal_service_fault.InternalServiceFault: <p>Request processing has failed due to some unknown error, exception, or failure.</p>
        capo_cloudwatch.errors.invalid_parameter_value_exception.InvalidParameterValueException: <p>The value of an input parameter is bad or out-of-range.</p>
        capo_cloudwatch.errors.resource_not_found_exception.ResourceNotFoundException: <p>The named resource does not exist.</p>
        capo_cloudwatch.errors.UnknownServiceError: The service returned an error code this client does not model.
    """

    def _handler(
        req: "OperationRequest[capo_cloudwatch.types.tag_resource_input.TagResourceInput]",
    ) -> OperationResponse[
        "capo_cloudwatch.types.tag_resource_output.TagResourceOutput"
    ]:
        import capo_cloudwatch._operations.granite_service_version20100801.tag_resource

        output, http_response = (
            capo_cloudwatch._operations.granite_service_version20100801.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_cloudwatch.types.tag_resource_input.TagResourceInput = {}
    if resource_arn is not None:
        input_["resource_arn"] = resource_arn
    if tags is not None:
        input_["tags"] = tags

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