Skip to content

Using a !If on and Event Timer for Enabled is always True #2150

Closed

Description

@jwalsh2me

Description

I have a Condition in my SAM Template to check the ENV Parameter it True. I am trying to pass that into a Timer Event to either be true or false under Enabled. It always sends it as true. Setting that value to either true or false works as expected, but using Enabled: !If [ProdEnv, "false", "false"] or Enabled: !If [ProdEnv, "true", "false"] always sets it to true and enabled.

Steps to reproduce

SAM CLI, version 1.0.0

snipped template:

<SNIP>
Parameters:
  ENV:
    Type: String
    Default: prod
    AllowedValues:
      - prod
      - stage
  ProdDbKMSKeyID:
    Type: "AWS::SSM::Parameter::Value<String>"
    Default: "/db/prod/KMSKeyID"
  NonProdKMSKeyID:
    Type: "AWS::SSM::Parameter::Value<String>"
    Default: "/db/nonprod/KMSKeyID"
  VendorsKMSKeyID:
    Type: "AWS::SSM::Parameter::Value<String>"
    Default: "/vendors-prod-lambda/KMSKeyID"

Conditions:
  ProdEnv: !Equals [!Ref ENV, prod]
 Environment:
        Variables:
          app_env: !Ref ENV
          dbhost: !Sub "{{resolve:ssm:/db/${ENV}/edw/hostname:1}}"
          dbuser: !Sub "{{resolve:ssm:/db/${ENV}/edw/lambda_user:1}}"
          dbname: !Sub "{{resolve:ssm:/db/${ENV}/edw/dbname:1}}"
          <SNIP>
      VpcConfig:
        SecurityGroupIds:
          - <removed>
        SubnetIds:
          - <removed>
          - <removed>
      Events:
        Timer:
          Type: Schedule
          Properties:
            Schedule: cron(00 16 ? * MON,WED *) 
            Description: sFTP
            Enabled: !If [ProdEnv, true, false]
      Policies:
        - AWSLambdaExecute
        - VPCAccessPolicy: {}
        - KMSDecryptPolicy:
            KeyId: !If [ProdEnv, !Ref ProdDbKMSKeyID, !Ref NonProdKMSKeyID]
        - KMSDecryptPolicy:
            KeyId: !Ref VendorsKMSKeyID
<SNIP>

Observed result

The ENV is set to be stage, other !If work as expected above however the Timer is set to be Enabled.

Now if I skip the !If and just pass a true or false to Enabled it works as expected. So I am not sure if this is just not supported for the Timer or if there is a problem with the transform.

Expected result

I expected the Timer to have been set to false.

      Events:
        Timer:
          Type: Schedule
          Properties:
            Schedule: cron(00 16 ? * MON,WED *) 
            Description: sFTP
            Enabled: !If [ProdEnv, true, false]

Additional environment details (Ex: Windows, Mac, Amazon Linux etc)

  1. OS: macOS 10.15.6
  2. sam --version: 1.0.0

Add --debug flag to command you are running

Activity

  1. jwalsh2me commented on Aug 1, 2020

    @jwalsh2me
    Author

    Also tried a !Ref ProdEnv to see if that would pass the True/False it was also always True.

  2. timoschilling commented on Aug 3, 2020

    @timoschilling
    Contributor
  3. jwalsh2me commented on Aug 3, 2020

    @jwalsh2me
    Author

    Thanks @timoschilling will open up an issue there and link it back here.

  4. jwalsh2me commented on Aug 3, 2020

    @jwalsh2me
    Author
  5. jfuss commented on Aug 7, 2020

    @jfuss
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions