AWS yaml set schedule based on env

Viewed 28

I have a serverless.yaml file that has a scheduled lambda function. I'm trying to define the cron schedule based on the env. In my yaml file I've set custom values like so

custom:
  node_env: ${opt:stage, self:provider.stage}
  provider:
    production:
      testKey: value
    stage:  
      testKey: value
    development:    
      testKey: value

And I am accessing these values in the same yaml file in the following format.

${self:custom.provider.${self:custom.node_env}.testKey}

This works fine for the most part.

I tried setting up the cron scheduler in a similar fashion but that unfortunately did not work. I'm not sure how to go about it.

functions:
  scheduleJobFunc:
    handler: src/scheduleJob
    events:
      - schedule:
          rate: ${self:custom.provider.${self:custom.node_env}.cron}
          enabled: true

custom:
  node_env: ${opt:stage, self:provider.stage}
  provider:
    production:
      testKey: value
      cron: cron(0 0 1 * ? *)
    stage:  
      testKey: value
      cron: cron(0 0 1 * ? *)
    development:    
      testKey: value
      cron: cron(0 0 1 * ? *)
0 Answers
Related