python - 相当于 aws cdk 中的 !Ref

标签 python amazon-web-services aws-cloudformation aws-cdk

我目前正在使用 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/

相关文章:

amazon-web-services - 使用 AWS::include 和嵌套堆栈编写可重用的 CloudFormation 片段

amazon-web-services - 如何在Cloudformation中使用Route53创建动态数量的子域?

Python FFMPEG AttributeError : 'Popen' object has no attribute 'proc'

python - `assert 1,2 == (2,3)` 不会在 python3 中引发 AssertionError

discord.py : ssl. SSLCertVerificationError : certificate verify failed: unable to get local issuer certificate (_ssl. c:1056 上的 Python SSL 错误

php - 设置从 EBS 共享加载文件的超时

python - 给定日期后的 DatetimeField 过滤器

java - 如何使用别名获取KMS KeyId?

java - 使用 S3 DeleteObject 仅删除文件,保持目录结构不变

dockerfile - ECS Fargate 日志文件位置