title: AWS Lambda - Stage based event triggers
body: <p>I'm working on an AWS Lambda using the serverless framework. I'm trying to get my Lambda function to run on an EventBridge trigger, more specifically a cron schedule. The schedule being to run every 30 minutes between 20:00 and 07:00 Mon-Friday. However, this is great for prod, but in QA/UAT I want a different cron schedule (most likely). Thus I'm looking to implement stage based cron triggers so that I can schedule it for the day time in QA/UAT, but schedule it for the evening in production.</p>
  <p>I originally tried a single cron schedule trigger of cron (<code>0/30 20:30-06:30 ? * 1-5 *</code>) for UAT, but that didn't work for some reason. My Lambda function ran only twice after 20:30, which I've yet to figure out.</p>
  <p>My serverless file contains:</p>
  <pre><code>custom:
    stage: &quot;${opt:stage, self:provider.stage, 'dev'}&quot;
    stages: 
      - dev
      - uat
    eveningSchedule: 
      dev: cron(0/30 08:00-12:59 ? * 1-5 *)
      uat: cron(0/30 20:30-23:59 ? * 1-5 *)
    morningSchedule:
      dev: cron(0/30 12:01-17:30 ? * 1-5 *)
      uat: cron(0/30 00:30-06:30 ? * 1-5 *)
  </code></pre>
  <p>The function is defined as :</p>
  <pre><code>functions:
    handler123:
      handler: foo::bar::functionName
  
      package:
        artifact: ./bin/Release/net6.0/foo.bar.zip
      
      events:
            - schedule: &quot;${self:custom.eveningSchedule.stage}&quot; 
            - schedule: &quot;${self:custom.morningSchedule.stage}&quot;
  </code></pre>
  <p>The error I get when running sls deploy is:</p>
  <blockquote>
  <p>Cannot resolve variable at &quot;functions.CifFileRetriever.events.0&quot;: Value not found at &quot;self&quot; source and &quot;functions.CifFileRetriever.events.1&quot;: Value not found at &quot;self&quot;</p>
  </blockquote>
  <p>Would be massively grateful for any help on this one.</p>