简体   繁体   English

AWS:如何在CloudFormation模板中指定布尔参数

[英]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次或StringAllowedValues “真”与“假”?

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 . 快速入门模板是一个很好的,半官方的参考点,表明可以/应该如何创建复杂模板,它们完全按照您的描述为条件资源实现布尔值,使用带有AllowedValuesStringtruefalse 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文档中的现有资源示例中找到,其中AllowedValuesdefaultNONE (默认值)。

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.

相关问题 AWS CloudFormation 模板:如何隐藏参数? - AWS CloudFormation‎ Template : How to hide parameter? 在CloudFormation模板中为“ AWS :: ApiGateway :: Resource”指定ParentId - Specify ParentId for “AWS::ApiGateway::Resource” in CloudFormation template 如何在 Cloudformation 模板条件中使用 AWS SSM 参数存储值? - How to use AWS SSM parameter store values in Cloudformation template conditionals? 如何在 aws cloudformation yaml 模板中格式化数据类型 json 的参数? - How to format parameter of data type json in a aws cloudformation yaml template? AWS Parameter Store 结果作为 CloudFormation 模板中的列表 - AWS Parameter Store result as list in CloudFormation template AWS CloudFormation模板缺少什么参数? - What parameter is missing for AWS CloudFormation template? 如何在AWS :: EMR :: Cluster CloudFormation模板中指定Ec2实例属性? - How to specify Ec2 Instance Attributes in a AWS::EMR::Cluster CloudFormation Template? 如何使用Cloudformation在AWS Aurora中指定Postgres? - How to specify Postgres in AWS Aurora using Cloudformation? AWS ECS-无法在cloudformation模板中指定服务名称 - AWS ECS - Unable to specify service name in cloudformation template 是否可以在 cloudformation 模板中静态指定 AWS::StackName? - Is it possible to statically specify AWS::StackName inside a cloudformation template?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM