Skip to content

sam incorrectly resolve parameters #1360

Closed

Description

@mgorski-mg

I have a problem to pass parameters to enable or disable Lambda Scheduler

Template:

Parameters:
  SchedulerCronParameter:
    Type: String
    Description: Enter scheduler cron expresion. Default is cron(0 1 1 * ? *).
    Default: cron(0 1 1 * ? *)
  SchedulerEnabledParameter:
    Type: String
    Description: Enable or disable scheduler. Default is true.
    Default: true
    AllowedValues: [true, false]

Resources:
  ScheduledLambda:
    Type: AWS::Serverless::Function
    Properties:
      CodeUri: code/
      Handler: handler.lambda_handler
      Runtime: python3.7
      Timeout: 900
      Tracing: Active
      Events:
        Schedule:
          Properties:
            Name: LambdaScheduler
            Description: Monthly schedule
            **Enabled: !Ref SchedulerEnabledParameter**
            Schedule: !Ref SchedulerCronParameter
            Input: '{"view_only": false}'
          Type: Schedule

I think it's because the template is translated before resolving CF Parameters.
Code from SAM translator:

if self.Enabled is not None:
            events_rule.State = "ENABLED" if self.Enabled else "DISABLED"

If the Parameter is not resolved before translation, it's always set State as 'ENABLED'.

Do you have any workaround for it?

SAM CLI version: 0.39.0

Activity

  1. jfuss commented on Jan 3, 2020

    @jfuss
    Contributor

    @mgorski-mg Thanks for the issue. I think this has to do with how the spec works and not specifically the deploy command. I am going to forward this over to the SAM Translator (Spec) repo for further help.

  2. transferred this issue fromaws/aws-sam-clion Jan 3, 2020
  3. mgorski-mg commented on Jan 3, 2020

    @mgorski-mg
    Author

    @jfuss true that 😅 Thx!

  4. changed the title [-]sam deploy incorrectly resolve parameters[/-] [+]sam incorrectly resolve parameters[/+] on Jan 5, 2020
  5. soccerboymalloy-patriot commented on Jun 19, 2020

    @soccerboymalloy-patriot

    Any updates or workarounds for this? We have a Lambda that we'd like to schedule in our Production account, but not in our Development account. We're trying to use TemplateConfiguration files in our CodePipeline in order to set this value. This bug is preventing us from disabling the schedule in our Development account.

    I suppose we could define two Lambdas in our template (one with a schedule and one without) that get conditionally created based on the environment. But that's brittle, error prone, and ugly.

  6. mgorski-mg commented on Jun 19, 2020

    @mgorski-mg
    Author

    Any updates or workarounds for this? We have a Lambda that we'd like to schedule in our Production account, but not in our Development account. We're trying to use TemplateConfiguration files in our CodePipeline in order to set this value. This bug is preventing us from disabling the schedule in our Development account.

    I suppose we could define two Lambdas in our template (one with a schedule and one without) that get conditionally created based on the environment. But that's brittle, error prone, and ugly.

    You can define the scheduler using classic CloudFormation instead of the SAM.
    You need to define AWS::Events::Rule and AWS::Lambda::Permission.
    Then you can use parameters properly.

  7. soccerboymalloy-patriot commented on Jun 22, 2020

    @soccerboymalloy-patriot

    You can define the scheduler using classic CloudFormation instead of the SAM.
    You need to define AWS::Events::Rule and AWS::Lambda::Permission.
    Then you can use parameters properly.

    Thanks for the pointer! Sometimes I forget that I can mix and match CloudFormation and SAM. For reference, this documentation is exactly what I needed.

  8. diegogurpegui commented on Sep 26, 2020

    @diegogurpegui

    I just came across this issue.
    Any update or progress? or the solution at the moment is still the one suggested by @mgorski-mg?

  9. RichieRunner commented on Jan 19, 2021

    @RichieRunner

    I just came across this issue.
    Any update or progress? or the solution at the moment is still the one suggested by @mgorski-mg?

    There's been no fix for this after 1 year, but there's a workaround discussed here

  10. ckabalan commented on Sep 21, 2021

    @ckabalan

    I just tried this today and it is still broken. The workaround by @mgorski-mg continues to work.

  11. added
    area/intrinsics
    on Mar 29, 2022
  12. Yop-La commented on Apr 26, 2022

    @Yop-La

    The same on my side. The issue is still here.

  13. hoffa commented on Oct 17, 2022

    @hoffa
    Contributor

    You might be able to get this to work by adding AWS::LanguageExtensions to Transform as such:

    Transform:
      - AWS::LanguageExtensions
      - AWS::Serverless-2016-10-31

    AWS::LanguageExtensions resolves intrinsic functions if the value is known when Transforms are run.

    See #2533 for more information.

  14. hoffa commented on Nov 3, 2022

    @hoffa
    Contributor

    Closing in favor of #2533.

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

    area/intrinsicstype/feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions