AWS CDK Python有条件地创建资源

2024-05-23 17:31:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我想根据参数值创建资源。我怎样才能做到这一点

例如:

vpc_create = core.CfnParameter(stack, "createVPC")
condition = core.CfnCondition(stack, 
                             "testeCondition",
                              expression=core.Fn.condition_equals(vpc_create, True)
)
vpc = ec2.Vpc(stack, "MyVpc", max_azs=3)

如果参数为true,如何为正在创建的VPC向VPC资源添加条件

我认为我需要获得云信息资源,类似这样的东西:

vpc.node.default_child # And I think this returns an object from ec2.CfnVPC class, but I'm stuck here.

谢谢


Tags: corestackcreate资源ec2conditionvpcfn
1条回答
网友
1楼 · 发布于 2024-05-23 17:31:28

使用context数据可以有条件地创建资源和许多其他灵活性。AWS本身建议context优于parameters

In general, we recommend against using AWS CloudFormation parameters with the AWS CDK. Unlike context values or environment variables, the usual way to pass values into your AWS CDK apps without hard-coding them, parameter values are not available at synthesis time, and thus cannot be easily used in other parts of your AWS CDK app, particularly for control flow.

请在https://docs.aws.amazon.com/cdk/latest/guide/parameters.html全文阅读

相关问题 更多 >