How to add a tag to an AWS-CDK construct

后端 未结 4 1345
孤街浪徒
孤街浪徒 2021-01-19 21:22

How to add a tag to an AWS-CDK specific construct or even better one tag definition to all ressources created within the stack?

4条回答
  •  佛祖请我去吃肉
    2021-01-19 22:11

    The above answers use the deprecated syntax.

    Newer version of tagging the whole App:

    const app = new cdk.App();
    new SomeStack(app, 'SomeStack');
    Tags.of(app).add("app", "my-app-name-here");
    

    You could also tag individual stacks only:

    const app = new cdk.App();
    const stack = new SomeStack(app, 'SomeStack');
    Tags.of(stack).add("stack-name", "SomeStack");
    

    Or individual Constructs:

    const usersTable = new dynamodb.Table(this, 'Users');
    Tags.of(usersTable).add("owner", "team-andromeda");
    

    Tags will apply to sub-Constructs hierarchically.

提交回复
热议问题