Possible to specify events for specific environment only for AWS Lambda?

    events:
      - schedule: cron(0 02 * * ? *) # Timezone: UTC

I want to set a reoccurring event but only in Production environment. Is that possible to configure int eh Serverless.yaml?

You can take a look on the serverless-plugin-ifelse

custom:
  myStage: ${opt:stage, self:provider.stage}
  serverlessIfElse:
        # Deploy schedule only in production env
        - If: '"${self:custom.myStage}" != "production"'
          Exclude:
            - functions.yourfunction.events.0.schedule
1 Like

Thanks, however managed to figure it out as:

custom:
  stage: "${opt:stage, self:provider.stage}"
  prod:
    schedule: cron(0 02 * * ? *) # Timezone: UTC; Only run schedule in prod
  dev:
    schedule:
  test:
    schedule:
  qa:
    schedule:

And then for the Function:

events:
  - schedule: ${self:custom.${self:custom.stage}.schedule}
3 Likes

When I try to take this strategy, Iā€™m getting a warning (which will soon be an error in a new version)

`A valid service attribute to satisfy the declaration 'self:custom.dev.myVariableName'    could not be found.`

because I have that empty, as you showed above. How did you get around that?