【发布时间】:2016-12-29 09:47:29
【问题描述】:
我正在使用平台条件来控制在 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。
"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 资源。
我使用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.
是否可以评估多个条件来控制资源创建?如果没有,我可以尝试其他选择吗?
【问题讨论】:
-
我在使用 Fn::And 时遇到了同样的问题 - 只想添加此评论,以便下一个使用谷歌搜索“Fn::And”的人会发现这个页面比我更容易:)
标签: amazon-web-services amazon-ec2 amazon-cloudformation