amazon-web-servicesconditional-statementsaws-cloudformation

Cloudformation Conditional Fails with expected type: JSONObject, found: JSONArray


I've read a bunch of threads here and other places but can't determine what I'm missing here.

Trying to deploy a DynamoDB Global table, however we have only one region in our lower development environment and multiple regions in our upper environments. I'm trying to use a Condition and a conditional If to only deploy the second replica in the environments with multiple regions.

Condition:
  HasMultipleRegions:
    !Not [!Equals [!Ref Environment, "development"]]
Resources:
  MyGlobalTable:
    Type: 'AWS::DynamoDB::GlobalTable'
    Properties:
      TableName: MyGlobalTable
      BillingMode: !Ref BillingMode
      StreamSpecification:
        StreamViewType: !Ref StreamViewType
      AttributeDefinitions:
        - AttributeName: attribute_a
      AttributeType: N
      KeySchema:
        - AttributeName: attribute_a
      KeyType: HASHS
      SESpecification:
        SSEEnabled: true
        SSEType: KMS
      Replicas:
        - Region: !Ref Region1
          PointInTimeRecoverySpecification:
            PointInTimeRecoveryEnabled: true
          SSESpecification:
            KMSMasterKeyId: !Ref KmsKeyIdRegion1
        - !If
          - HasMultipleRegions
          - - Region: !Ref Region2
              PointInTimeRecoverySpecification:
                PointInTimeRecoveryEnabled: true
              SSESpecification:
                KMSMasterKeyId: !Ref KmsKeyIdRegion2
          - Ref: "AWS::NoValue"

From what I've read, I think it has something to do with the way I'm defining my 'If' and my indentations, but I've tried a lot of things, moving the If around, using Fn::If, etc and either get the listed error or get parsing errors. Thought this was not a list so tried using !If instead of - !If but then I get parsing errors similar to this one.


Solution

  • You don't need second -. It should be:

            - !If
              - HasMultipleRegions
              - Region: !Ref Region2
                PointInTimeRecoverySpecification:
                  PointInTimeRecoveryEnabled: true
                SSESpecification:
                  KMSMasterKeyId: !Ref KmsKeyIdRegion2
              - Ref: "AWS::NoValue"