class TagManager
Language | Type name |
---|---|
.NET | Amazon.CDK.TagManager |
Java | software.amazon.awscdk.core.TagManager |
Python | aws_cdk.core.TagManager |
TypeScript (source) | @aws-cdk/core » 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
import * as cdk from '@aws-cdk/core';
class MyConstruct extends cdk.Resource implements cdk.ITaggable {
public readonly tags = new cdk.TagManager(cdk.TagType.KEY_VALUE, 'Whatever::The::Type');
constructor(scope: cdk.Construct, id: string) {
super(scope, id);
new cdk.CfnResource(this, 'Resource', {
type: 'Whatever::The::Type',
properties: {
// ...
Tags: this.tags.renderedTags,
},
});
}
}
Initializer
new TagManager(tagType: TagType, resourceTypeName: string, tagStructure?: any, options?: TagManagerOptions)
Parameters
- tagType
Tag
Type - resourceTypeName
string
- tagStructure
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. |
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()
renderpublic renderTags(): 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.