如何将标签添加到AWS-CDK构造 [英] How to add a tag to an AWS-CDK construct

查看:64
本文介绍了如何将标签添加到AWS-CDK构造的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将标签添加到特定于AWS-CDK的构造中,或者甚至向堆栈中创建的所有资源添加更好的标签定义?

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

推荐答案

根据aws-cdk文档,您可以将标记添加到所有构造/资源.标签将继承到同一树"中的构造.太酷了.

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.

使用基于Java的aws-cdk的示例:

Example using aws-cdk based on java:

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

AWS-Doc CDK标记

标签可以应用于任何结构.标签是继承的,基于范围.如果标记结构A,并且A包含结构B,则结构B继承标签.

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.

aws-cdk文档中的示例:

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');

这篇关于如何将标签添加到AWS-CDK构造的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆