Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure eventbridge rule in serverless.yml (using serverless framework ) to invoke lambda on specific time

We have already python lambda function running with AWS eventbridge which was configured manually using console to trigger lambda on 9 PM everyday. Currently, we also have rule arn for eventbridge.

Plan:

So, We are migrating everything to serverless framework to automate the whole lambda deployment and configuring eventbridge using serverless.yml to invoke the lambda on 9 pm.

Can anyone please advise how do I do that ?

Sample code:

functions:
  myFunction:
    handler: index.handler
    events:
      - eventBridge:
          --------
          --------
          --------
like image 951
Mase456 Avatar asked Sep 12 '25 02:09

Mase456


1 Answers

There is documentation at serverless.com that describes this. All you do is add the cron schedule to the EventBridge event as if it was a schedule event. For example:

functions:
  myFunction:
    handler: index.handler
    events:
      - eventBridge:
          schedule: cron(0 12 * * ? *)
          input:
            key1: value1

You can find the documentation for EventBridge here: https://www.serverless.com/framework/docs/providers/aws/events/event-bridge

And for the Schedule event with an example of a cron schedule here: https://www.serverless.com/framework/docs/providers/aws/events/schedule

like image 58
Gareth McCumskey Avatar answered Sep 16 '25 06:09

Gareth McCumskey