Rob*_*ole 3 python amazon-web-services aws-cloudformation aws-cdk
我目前正在使用 aws-cdk 生成 cloudformation 模板,我想访问使用 定义的参数
CfnParameter(self, id="Platform", type="String", default="My Platform")
Run Code Online (Sandbox Code Playgroud)
带有参考(就像!Ref Platform 在 cloudformation 模板中一样)
你们中的任何人都知道 aws cdk 中的 Ref 相当于什么。
这是我上面定义的参数的 yaml 等效项
Parameters:
Platform:
Type: String
Default: "My Platform"
Run Code Online (Sandbox Code Playgroud)
这取决于您使用的构造。
对于低级构造,即所谓的 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,
...
)
Run Code Online (Sandbox Code Playgroud)