How to add a tag to an AWS-CDK construct

后端 未结 4 1420
孤街浪徒
孤街浪徒 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:07

    According to aws-cdk doc you can add a tag to all constructs/ressources. Tags will inherits to constructs within same "tree". That's pretty cool.

    Example using aws-cdk based on java:

    MyStack stack = new MyStack(app, "nameOfStack");
    Tag.add(stack, "tag_foo", "tag_foo");
    

    AWS-Doc CDK Tagging

    AWS CDK Reference: Tag

    Tags can be applied to any construct. Tags are inherited, based on the scope. If you tag construct A, and A contains construct B, construct B inherits the tag.

    Example from aws-cdk doc:

    import { App, Stack, Tag } from require('@aws-cdk/core');
    
    const app = new App();
    const theBestStack = new Stack(app, 'MarketingSystem');
    
    // Add a tag to all constructs in the stack
    Tag.add(theBestStack, 'StackType', 'TheBest');
    

提交回复
热议问题