我目前正在使用 aws-cdk 生成 cloudformation 模板,我想访问定义的参数
CfnParameter(self, id="Platform", type="String", default="My Platform")
带有引用(例如cloudformation模板中的!Ref Platform
)
你们中的任何人都知道 aws cdk 中的 Ref 相当于什么。
这是我上面定义的参数的 yaml 等效项
Parameters:
Platform:
Type: String
Default: "My Platform"
最佳答案
这取决于您使用的构造。
对于低级构造,即所谓的 CFN 资源,您可以使用 ref
属性。
对于高级构造,您应该检查 API 中的 xxx_id 属性。
在下面的示例中,cfn 资源使用 ref
属性,而高级 VPC 构造使用 vpc_id
属性。
my_vpc = _ec2.Vpc(
tgw = _ec2.CfnTransitGateway(...)
tgw_attachment = _ec2.CfnTransitGatewayAttachment(
self,
id="tgw-myvpc",
transit_gateway_id=tgw.ref,
vpc_id=my_vpc.vpc_id,
...
)
关于python - 相当于 aws cdk 中的 !Ref,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58997233/