等同于aws cdk中的!Ref

问题描述 投票:0回答:1

我目前正在使用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"
python amazon-web-services amazon-cloudformation aws-cdk
1个回答
0
投票

取决于您使用的是哪种构造。

对于低级构造,即所谓的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,
            ...
)
© www.soinside.com 2019 - 2024. All rights reserved.