class TagManager
Language | Type name |
---|---|
.NET | Amazon.CDK.TagManager |
Go | github.com/aws/aws-cdk-go/awscdk/v2#TagManager |
Java | software.amazon.awscdk.TagManager |
Python | aws_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
Tag
Type - resourceTypeName
string
- initialTags
any
- options
Tag
Manager Options
Properties
Name | Type | Description |
---|---|---|
rendered | IResolvable | A lazy value that represents the rendered tags at synthesis time. |
tag | string | The 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
Name | Description |
---|---|
apply | Determine if the aspect applies here. |
has | Returns true if there are any tags defined. |
remove | Removes the specified tag from the array if it exists. |
render | Renders tags into the proper format based on TagType. |
set | Adds the specified tag to the array of tags. |
tag | Render the tags in a readable format. |
static is | Check whether the given construct is Taggable. |
static is | Check whether the given construct is ITaggableV2. |
static of(construct) | Return the TagManager associated with the given construct, if any. |
TagAspectHere(include?, exclude?)
applypublic 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
Tags()
haspublic hasTags(): boolean
Returns
boolean
Returns true if there are any tags defined.
Tag(key, priority)
removepublic 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.
Tags(combineWithTags?)
renderpublic 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.
Tag(key, value, priority?, applyToLaunchedInstances?)
setpublic 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.
Values()
tagpublic tagValues(): { [string]: string }
Returns
{ [string]: string }
Render the tags in a readable format.
Taggable(construct)
static ispublic static isTaggable(construct: any): boolean
Parameters
- construct
any
Returns
boolean
Check whether the given construct is Taggable.
TaggableV2(construct)
static ispublic 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
Return the TagManager associated with the given construct, if any.