AWS: How to specify a boolean parameter in a CloudFormation template

Solution 1:

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. 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).

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.

Here's a complete, minimal example template:

Launch Stack

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