相关疑难解决方法(0)

基于 DependsOn 的 AWS 云形成条件

我正在编写一个云形成模板,并且在我的堆栈中创建一个资源取决于环境。
因此,我检查参数(环境)的值,并基于它创建该资源(条件: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
Run Code Online (Sandbox Code Playgroud)

我的问题是,只有当 ISProduction 为真时,我才希望 AnotherResource 依赖于 MyProductionResource。一个想法是在 DependsOn 项中添加某种条件,或者任何可以带来相同结果的条件。
我如何在 AWS Cloud Formation 上做到这一点?
此外,我不确定当未创建dependsOn 列表中列出的资源时会发生什么。云形成模板会产生错误吗?我怎样才能使这个属性读取安全!GetAtt MyProductionResource.Outputs.SomeString ?

cloud amazon-web-services aws-cloudformation

2
推荐指数
1
解决办法
3671
查看次数