【发布时间】:2017-04-27 07:27:34
【问题描述】:
我正在编写一个云形成模板,并且在我的堆栈中创建一个资源取决于环境。
因此,我检查一个参数(环境)的值,并基于它创建该资源(条件:ISProduction)。
但是,我的问题是,如果创建了该资源 (MyProductionResource),另一个资源 (AnotherResource) 将依赖于它,并且需要使用另一个 (MyProductionResource) 的输出属性。
代码如下:
Conditions:
ISProduction:
"Fn::Equals":
- !Ref Environment
- production
...
MyProductionResource:
Type: AWS::CloudFormation::Stack
Condition: ISProduction
Properties:
[.. properties..]
AnotherResource:
Type: AWS::CloudFormation::Stack
DependsOn:
- AResource
- MyProductionResource
Properties:
TemplateURL: whatever
Parameters:
AParameter: !GetAtt MyProductionResource.Outputs.SomeString
我的问题是,仅当 ISProduction 为 true 时,我才希望 AnotherResource 依赖于 MyProductionResource。一个想法是在 DependsOn 项目中添加某种条件,或者任何会带来相同结果的条件。
如何在 AWS Cloud Formation 上做到这一点?
此外,我不确定当未创建 dependsOn 列表中列出的资源时会发生什么。云形成模板会产生错误吗?如何让这个属性读取安全 !GetAtt MyProductionResource.Outputs.SomeString ?
【问题讨论】:
标签: amazon-web-services cloud amazon-cloudformation