3

AWSでスピンアップされる環境のタイプを制御するためにプラットフォーム条件を使用しています。共有リソースはたくさんありますが、番号の条件に応じて事前に焼いたAMIを持つ特定のEC2インスタンスが必要です。クラウド形成リソース作成における複数の条件

"Parameters": { 
"Platform": { 
    "Description": "Select platform type - linux or windows", 
    "Default": "linux", 
    "Type": "String", 
    "AllowedValues": [ "linux", "windows", "both" ], 
    "ConstraintDescription": "Must enter either linux, windows, or both" 
}, 

次に、conditionsを設定しました。私はすべてのEC2のリソースを展開するには、WindowsまたはLinux Ec2と作成をトリガするためのLinuxまたはWindowsのいずれかを使用、またはその両方を使用したいリソースで

"Conditions" : { 
    "LinuxPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "linux"]}, 
    "WindowsPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "windows"]}, 
    "BothPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "both"]} 
}, 

を宣言しました。

私はいくつかの点でfn:orを使って以下を試しました。

"Fn::Or": [{"Condition": "LinuxPlatform"}, {"Condition": "BothPlatform" }],

と...

"Condition" : { 
    "Fn::Or" : [ 
     {"Condition" : "LinuxPlatform"}, 
     {"Condition" : "BothPlatform"} 
    ] 
} 

私はAWS CLIを使用して展開し、検証をしようとすると、次のエラーを取得しておきます。

aws cloudformation validate-template --template-body  file://./cloudformation/deploy.json 

A client error (ValidationError) occurred when calling the ValidateTemplate operation: Template format error: Every Condition member must be a string. 

リソース作成を制御するために複数の条件を評価することは可能ですか?そうでない場合は、私は試してみることができる選択肢は何ですか?そのようなあなたのConditionsの底に

"MyCondition": {"Fn::Or": [{"Condition": "LinuxPlatform"}, {"Condition": "BothPlatform" }]} 

を追加

答えて

4

試してみてください。

"Conditions" : { 
     "LinuxPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "linux"]}, 
     "WindowsPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "windows"]}, 
     "BothPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "both"]}, 
     "MyCondition": {"Fn::Or": [{"Condition": "LinuxPlatform"}, {"Condition": "BothPlatform" }]} 
    }, 
+0

おかげで、私はすぐにしようとするでしょう。スタックの作成中にドロップダウンからウィンドウを選択すると、テンプレート内のEC2リソースの50%が作成されるという構造です。私がLinuxを選択した場合、それは他の50%です。私は両方を選択して、主にデベロッパーとテスト目的のためにすべてのインスタンスをデプロイできるようにしたいと考えています。上記を使用して私がそれを可能にするか、またはウィンドウをfn ::に追加する必要がありますか? –

関連する問題