AWS Cloudformation: InvalidTemplateException `Every Condition member must be a string.`

16 views Asked by At
  • I use conditional resource creation for my lambda function.
  • When I try to build the template I get presented with the error InvalidTemplateException Every Condition member must be a string.. The CLI does not provide more details as to where something is wrong.
  • As my condition is a string, I'm not sure what is wrong.
Code:
Parameters:
  LocalExecution:
    Type: String
    Default: "false"

Conditions:
  IsLocalExecution: !Equals [ !Ref LocalExecution, 'true' ]

Resources:
  ProductionDeploy:
    Type: AWS::Serverless::Function
    Condition: !Not [ IsLocalExecution ]
    Properties: 
    ...

  LocalExecution:
    Type: AWS::Serverless::Function
    Condition: IsLocalExecution
    Properties: 
    ...
1

There are 1 answers

0
DarkTrick On
Problem

This is the problem: Condition: !Not [ IsLocalExecution ]

Solution

Create a new condition

IsNotLocalExecution: !Equals [ !Ref LocalExecution, 'false' ]

Use that condition instead:

  ProductionDeploy:
    Type: AWS::Serverless::Function
    Condition: IsNotLocalExecution
    Properties: 
    ...
Notes

As my condition is a string, I'm not sure what is wrong.

This was a misconception. !Not will turn the condition into a boolean value. It's not a string anymore.