TagManager

class aws_cdk.core.TagManager(tag_type, resource_type_name, tag_structure=None, *, tag_property_name=None)

Bases: object

TagManager facilitates a common implementation of tagging for Constructs.

Normally, you do not need to use this class, as the CloudFormation specification will indicate which resources are taggable. However, sometimes you will need this to make custom resources taggable. Used tagManager.renderedTags to obtain a value that will resolve to the tags at synthesis time.

Example:

import aws_cdk.core as cdk


class MyConstruct(cdk.Resourcecdk.ITaggable):

    def __init__(self, scope, id):
        super().__init__(scope, id)

        cdk.CfnResource(self, "Resource",
            type="Whatever::The::Type",
            properties={
                # ...
                "Tags": self.tags.rendered_tags
            }
        )
Parameters
  • tag_type (TagType) –

  • resource_type_name (str) –

  • tag_structure (Optional[Any]) –

  • tag_property_name (Optional[str]) – The name of the property in CloudFormation for these tags. Normally this is tags, but Cognito UserPool uses UserPoolTags Default: “tags”

Methods

apply_tag_aspect_here(include=None, exclude=None)

Determine if the aspect applies here.

Looks at the include and exclude resourceTypeName arrays to determine if the aspect applies here

Parameters
  • include (Optional[Sequence[str]]) –

  • exclude (Optional[Sequence[str]]) –

Return type

bool

has_tags()

Returns true if there are any tags defined.

Return type

bool

remove_tag(key, priority)

Removes the specified tag from the array if it exists.

Parameters
  • key (str) – The tag to remove.

  • priority (Union[int, float]) – The priority of the remove operation.

Return type

None

render_tags()

Renders tags into the proper format based on TagType.

This method will eagerly render the tags currently applied. In most cases, you should be using tagManager.renderedTags instead, which will return a Lazy value that will resolve to the correct tags at synthesis time.

Return type

Any

set_tag(key, value, priority=None, apply_to_launched_instances=None)

Adds the specified tag to the array of tags.

Parameters
  • key (str) –

  • value (str) –

  • priority (Union[int, float, None]) –

  • apply_to_launched_instances (Optional[bool]) –

Return type

None

tag_values()

Render the tags in a readable format.

Return type

Mapping[str, str]

Attributes

rendered_tags

A lazy value that represents the rendered tags at synthesis time.

If you need to make a custom construct taggable, use the value of this property to pass to the tags property of the underlying construct.

Return type

IResolvable

tag_property_name

The property name for tag values.

Normally this is tags but some resources choose a different name. Cognito UserPool uses UserPoolTags

Return type

str

Static Methods

classmethod is_taggable(construct)

Check whether the given construct is Taggable.

Parameters

construct (Any) –

Return type

bool