我正在寫一個雲形成模板,並在我的堆棧中創建資源取決於環境。
因此,我檢查參數(環境)的值,並基於它創建該資源(條件:ISProduction)。
但是,我的問題是,如果創建資源(MyProductionResource),另一個資源(AnotherResource)變得依賴於它並需要使用另一個資源(MyProductionResource)的輸出屬性。
下面的代碼:AWS雲形成條件取決於
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
我的問題是,我想AnotherResource依賴於MyProductionResource只有當ISProduction是真實的。一個想法是在DependsOn項目中添加某種條件,或者任何會帶來相同結果的條件。
我如何在AWS Cloud Formation上做到這一點?
此外,我不確定在dependsOn列表中列出的資源未創建時發生了什麼。雲形成模板會產生錯誤嗎?我怎樣才能使這個屬性讀取安全!GetAtt MyProductionResource.Outputs.SomeString?