0

I'm trying to enable/disable lambda scheduled event based on environment, and not having much luck. If the env is prod, it should enable the schedule, and if it's dev it should disable it. However, the schedule status doesn't obey the condition. It's currently enabled in dev, but the template doesn't disable it. If I set the Enabled property to false manually, the schedule status does change to disable. So not sure where I'm going wrong (or if what I'm trying to do is possible). Any help is greatly appreciated!

Parameters:
  env:
    Type: String

Conditions:
  isProd:
    !Equals [!Ref env, prod]

Resources:
  func:
    Type: AWS::Serverless::Function
    Properties:
      Events:
        ScheduledEvent:
          Type: Schedule
          Properties:
            Schedule: rate(5 minutes)
            Enabled: !If [isProd, true, false]
sjl
  • 43
  • 5

1 Answers1

3

Okay, so after a bit more searching, it looks like setting the Enabled property with conditional statements doesn't work so nice. The workaround I've put in place is to use conditional statements in the Schedule property.

ScheduledEvent:
  Type: Schedule
  Properties:
    Schedule: !If [isProd, "rate(5 minutes)", "cron(00 00 01 01 ? 1970)"]

Thanks to these posts for point me in the right direction:

Conditionally enabling an event schedule in AWS sam template file

Dynamically change event properties on aws cloudformation templates

sjl
  • 43
  • 5