云形成资源创建中的多个条件 [英] Multiple conditions in cloud formation resource creation
问题描述
我正在使用平台条件来控制在AWS上启动的环境类型。有很多共享资源,但是我需要某些EC2实例,这些实例具有预先烘焙的AMI,具体取决于许多条件。
I'm using a platform condition to control the type of environment that gets spun up on AWS. There are plenty of shared resources, but I need certain EC2 instances with pre-baked AMIs depending on a number conditions.
"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" : {
"LinuxPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "linux"]},
"WindowsPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "windows"]},
"BothPlatform" : {"Fn::Equals" : [{"Ref" : "Platform"}, "both"]}
},
在资源中,我想使用linux或windows来触发Windows或Linux Ec2的创建,或者同时使用这两者来部署声明的每个ec2资源。
In a resource I'd like to use either linux or windows to trigger a Windows or Linux Ec2 creation, or use both to deploy every ec2 resource declared.
我e通过几种方式使用 fn:or
进行了以下尝试。
I've tried the following using fn:or
in a few ways.
Fn: :Or:[{ Condition: LinuxPlatform},{ Condition: BothPlatform}],
和。 ..
"Condition" : {
"Fn::Or" : [
{"Condition" : "LinuxPlatform"},
{"Condition" : "BothPlatform"}
]
}
尝试使用aws cli进行部署和验证时,我不断收到以下错误。
I keep getting the following error when trying to deploying and validating using the 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.
是否可以评估多个条件来控制资源创建?如果没有其他选择,我可以尝试吗?
Is it possible to evaluate multiple conditions to control resource creation? If not are there any alternatives I could try?
推荐答案
尝试添加
"MyCondition": {"Fn::Or": [{"Condition": "LinuxPlatform"}, {"Condition": "BothPlatform" }]}
到条件
的底部,像这样:
"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" }]}
},
这篇关于云形成资源创建中的多个条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!