在 AWS CloudFormation 中,布尔值和布尔值字符串可以互换吗?

Are*_*rel 2 amazon-web-services aws-cloudformation

我对 AWS CloudFormation 如何处理布尔值和布尔值字符串感到困惑。

例如,就 CloudFormation 而言,'true'and true(或'false'and false)在逻辑上是等价的吗?我在他们的快速入门模板中看到了这两种情况的示例,这让我认为它们是(尽管我还没有找到这方面的文档)。

例如,在他们的模板中,quickstart-compliance-common/templates/vpc-product.template,他们定义了一个“String”类型的变量pSupportsNatGateway,(尽管它的默认值是文字值,true):

Parameters:
  ...
  pSupportsNatGateway:
    Description: Specifies whether this region supports NAT Gateway (this value is
      determined by the main stack if it is invoked from there)
    Type: String
    Default: true
Run Code Online (Sandbox Code Playgroud)

然后,在模板后面的条件中,将该参数(可能是字符串)与文字值进行比较true

Conditions:
  ...
  cSupportsNatGateway:
    !Equals
    - true
    - !Ref pSupportsNatGateway
Run Code Online (Sandbox Code Playgroud)

我的问题是,CloudFormation 如何比较文字值和这些值的字符串?AWS 文档中哪里定义了这个?

Are*_*rel 5

我不知道这是在哪里记录的,但是是的!就 CloudFormation 而言,文字布尔值(或数字)及其字符串值确实是等效的。

我创建了一个最小的 CloudFormation 模板来测试这一点:

---
AWSTemplateFormatVersion: 2010-09-09
Description: Test CloudFormation template

Parameters:

  pCreateCluster:
    Description: To create or not create?
    Type: String
    Default: 'true'
    AllowedValues:
    - 'true'
    - 'false'

Conditions:
  CreateClusterConditionTrue1:
    !Equals
    - !Ref pCreateCluster
    - 'true'

  CreateClusterConditionTrue2:
    !Equals
    - !Ref pCreateCluster
    - true

  CreateClusterConditionFalse1:
    !Equals
    - !Ref pCreateCluster
    - 'false'

  CreateClusterConditionFalse2:
    !Equals
    - !Ref pCreateCluster
    - false

Resources:

  rFargateCluster:
    Type: AWS::ECS::Cluster
    Condition: CreateClusterConditionTrue1
    Properties:
      ClusterName: "my-test-cluster"

Outputs:
  CreateClusterConditionTrue1:
    Value:
      !If
      - CreateClusterConditionTrue1
      - "The answer is True"
      - "The answer is False"
  CreateClusterConditionTrue2:
    Value:
      !If
      - CreateClusterConditionTrue2
      - "The answer is True"
      - "The answer is False"
  CreateClusterConditionFalse1:
    Value:
      !If
      - CreateClusterConditionFalse1
      - "The answer is True"
      - "The answer is False"
  CreateClusterConditionFalse2:
    Value:
      !If
      - CreateClusterConditionFalse2
      - "The answer is True"
      - "The answer is False"
...
Run Code Online (Sandbox Code Playgroud)

结果表明它们实际上是等价的:

Key                             Value
CreateClusterConditionTrue1     The answer is True      
CreateClusterConditionTrue2     The answer is True      
CreateClusterConditionFalse2    The answer is False     
CreateClusterConditionFalse1    The answer is False
Run Code Online (Sandbox Code Playgroud)