How to add a tag to an AWS-CDK construct

后端 未结 4 1333
孤街浪徒
孤街浪徒 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 21:55

    Using the Java SDK:

    public class CdkInitClusterApp {
        public static void main(final String[] args) {
            final App app = new App();
            final CdkInitClusterStack cdkInitClusterStack = new CdkInitClusterStack(app, "CdkInitClusterStack");
            Tag.add(cdkInitClusterStack, "Project", "Value");
            app.synth();
        }
    }
    

    Then recreate the jar

    mvn clean compile package
    

    And run the cdk diff for verify the changes, the output will be similar to the following one:

    (base) [alessiosavi@localhost cdk-init-cluster]$ cdk diff
                       CdkInitClusterStack
    Resources
    [~] AWS::DynamoDB::Table cdk-test-table cdktesttableB0274F47 
     └─ [+] Tags
         └─ [{"Key":"Project","Value":"Value"}]
    

提交回复
热议问题