aws-cdk-lib.TagManager

class TagManager

LanguageType name
.NETAmazon.CDK.TagManager
Gogithub.com/aws/aws-cdk-go/awscdk/v2#TagManager
Javasoftware.amazon.awscdk.TagManager
Pythonaws_cdk.TagManager
TypeScript (source)aws-cdk-lib » TagManager

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

class MyConstruct extends Resource implements ITaggable {
  public readonly tags = new TagManager(TagType.KEY_VALUE, 'Whatever::The::Type');

  constructor(scope: Construct, id: string) {
    super(scope, id);

    new CfnResource(this, 'Resource', {
      type: 'Whatever::The::Type',
      properties: {
        // ...
        Tags: this.tags.renderedTags,
      },
    });
  }
}

Initializer

new TagManager(tagType: TagType, resourceTypeName: string, initialTags?: any, options?: TagManagerOptions)

Parameters

  • tagType TagType
  • resourceTypeName string
  • initialTags any
  • options TagManagerOptions

Properties

NameTypeDescription
renderedTagsIResolvableA lazy value that represents the rendered tags at synthesis time.
tagPropertyNamestringThe property name for tag values.

renderedTags

Type: IResolvable

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.


tagPropertyName

Type: string

The property name for tag values.

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

Methods

NameDescription
applyTagAspectHere(include?, exclude?)Determine if the aspect applies here.
hasTags()Returns true if there are any tags defined.
removeTag(key, priority)Removes the specified tag from the array if it exists.
renderTags(combineWithTags?)Renders tags into the proper format based on TagType.
setTag(key, value, priority?, applyToLaunchedInstances?)Adds the specified tag to the array of tags.
tagValues()Render the tags in a readable format.
static isTaggable(construct)Check whether the given construct is Taggable.
static isTaggableV2(construct)Check whether the given construct is ITaggableV2.
static of(construct)Return the TagManager associated with the given construct, if any.

applyTagAspectHere(include?, exclude?)

public applyTagAspectHere(include?: string[], exclude?: string[]): boolean

Parameters

  • include string[]
  • exclude string[]

Returns

  • boolean

Determine if the aspect applies here.

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


hasTags()

public hasTags(): boolean

Returns

  • boolean

Returns true if there are any tags defined.


removeTag(key, priority)

public removeTag(key: string, priority: number): void

Parameters

  • key string — The tag to remove.
  • priority number — The priority of the remove operation.

Removes the specified tag from the array if it exists.


renderTags(combineWithTags?)

public renderTags(combineWithTags?: any): any

Parameters

  • combineWithTags any

Returns

  • any

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.


setTag(key, value, priority?, applyToLaunchedInstances?)

public setTag(key: string, value: string, priority?: number, applyToLaunchedInstances?: boolean): void

Parameters

  • key string
  • value string
  • priority number
  • applyToLaunchedInstances boolean

Adds the specified tag to the array of tags.


tagValues()

public tagValues(): { [string]: string }

Returns

  • { [string]: string }

Render the tags in a readable format.


static isTaggable(construct)

public static isTaggable(construct: any): boolean

Parameters

  • construct any

Returns

  • boolean

Check whether the given construct is Taggable.


static isTaggableV2(construct)

public static isTaggableV2(construct: any): boolean

Parameters

  • construct any

Returns

  • boolean

Check whether the given construct is ITaggableV2.


static of(construct)

public static of(construct: any): TagManager

Parameters

  • construct any

Returns

  • TagManager

Return the TagManager associated with the given construct, if any.