简体   繁体   English

如何通过 AWS CDK CfnResource 访问标签值?

[英]How to access a tag value through AWS CDK CfnResource?

While experimenting with AWS CDK for Python I do not seem to be able to extract a tag value from a CfnResource.在尝试使用适用于 Python 的 AWS CDK 时,我似乎无法从 CfnResource 中提取标签值。

Example VPC (I understand that the core focus is on ec2.VPC, but it is just an experiment):示例VPC(我理解核心重点是ec2.VPC,但这只是一个实验):

vpc = ec2.CfnVPC(stack, 
              id = "vpc-id",
              cidr_block="10.1.0.0/16",
              enable_dns_hostnames=True,
              enable_dns_support=True,
              tags=[core.CfnTag(key="Name", value="vpc-name")])

How can I get to the value of the "Name" tag through CfnVPC construct?如何通过 CfnVPC 构造获取“Name”标签的值?

I have tried vpc.tags but it seems to give me TagManager that does not expose a get tag interface.我试过vpc.tags但它似乎给了我没有公开 get 标签接口的 TagManager。

What am I missing?我错过了什么?

I can created a tagged VPC using the AWS CDK 1.25.0 as below我可以使用 AWS CDK 1.25.0 创建一个标记的 VPC,如下所示

tagName = core.CfnTag(key="Name", value="Resource Name")
tagEnv = core.CfnTag(key="environment", value="production")
tagArr = [tagName, tagEnv]

vpc = ec2.CfnVPC(self, "test", cidr_block="192.168.5.0/24", tags=tagArr)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM