Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jwalsh2me opened this issue Jul 31, 2020 · 5 comments
Closed

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

jwalsh2me opened this issue Jul 31, 2020 · 5 comments

Comments

@jwalsh2me
Copy link

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

@jwalsh2me
Copy link
Author

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

@timoschilling
Copy link
Contributor

timoschilling commented Aug 3, 2020

I think it isn't a bug in SAM CLI it's a bug in https://github.com/awslabs/serverless-application-model

@jwalsh2me
Copy link
Author

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

@jwalsh2me
Copy link
Author

Moved to -->. aws/serverless-application-model#1676

@jfuss
Copy link
Contributor

jfuss commented Aug 7, 2020

Closing in favor of aws/serverless-application-model#1676

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants