[英]AWS: How to specify a boolean parameter in a CloudFormation template
I'm trying to specify a boolean parameter in a CloudFormation template so I can conditionally create resources based on a parameter passed in. 我正在尝试在CloudFormation模板中指定一个布尔参数,以便我可以根据传入的参数有条件地创建资源。
Looking at the documentation here and here it would appear there is a discernible lack of a boolean data type. 查看此处和此处的文档,可能会出现明显缺少布尔数据类型的情况。
What is best practice for specifying a boolean? 指定布尔值的最佳做法是什么? possibly
Number
with 0 or 1 or String
with AllowedValues
'true' and 'false'? 可能是
Number
0或1次或String
与AllowedValues
“真”与“假”?
The Quick Start templates are a good, semi-official reference point of how complex templates can/should be created, and they implement Boolean values for Conditional resources exactly as you described, using a String
with AllowedValues
true
and false
. 快速入门模板是一个很好的,半官方的参考点,表明可以/应该如何创建复杂模板,它们完全按照您的描述为条件资源实现布尔值,使用带有
AllowedValues
的String
为true
和false
。 Here's a specific example : 这是一个具体的例子 :
"EnableBanner": {
"AllowedValues": [
"true",
"false"
],
"Default": "false",
"Description": "To include a banner to be displayed when connecting via SSH to the bastion, set this parameter to true",
"Type": "String"
}
A similar example can be found in the Conditionally use an existing resource example from the CloudFormation documentation, where the AllowedValues
are default
or NONE
(the default). 类似的示例可以在条件使用
AllowedValues
文档中的现有资源示例中找到,其中AllowedValues
是default
或NONE
(默认值)。
To conditionally create a resource based on such a boolean parameter, you add a Condition statement containing a Fn::Equals
intrinsic function matching true
, then add a Condition
key to the resource. 要根据此类布尔参数有条件地创建资源,请添加包含与
true
匹配的Fn::Equals
内部函数的Condition语句,然后将Condition
键添加到资源。
Here's a complete, minimal example template: 这是一个完整的,最小的示例模板:
Parameters:
CreateResource:
Description: Whether I should create a resource.
Default: false
Type: String
AllowedValues: [true, false]
Conditions:
ShouldCreateResource:
!Equals [true, !Ref CreateResource]
Resources:
Resource:
Type: AWS::CloudFormation::WaitConditionHandle
Condition: ShouldCreateResource
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.