4

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:
          --------
          --------
          --------
Mase456
  • 100
  • 1
  • 7
  • You can read documentation https://www.serverless.com/framework/docs/providers/aws/events/schedule – gizemsever Nov 18 '21 at 04:07
  • @gizemsever Thanks for your suggestions. Well, what I am looking for is that how do i utilise the same eventbridge rule ARN in my serverless.yml which was configured manually via console to invoke lambda ? Is there anyway you can suggest plz. – Mase456 Nov 18 '21 at 04:27
  • You will need to entirely replace the existing set of resources deployed as the Serverless Framework will attempt to deploy from scratchusing a new CloudFormation stack and any existing resources with the same names will result in errors – Gareth McCumskey Nov 18 '21 at 08:20

2 Answers2

7

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

Gareth McCumskey
  • 1,510
  • 7
  • 12
1

In addition to @Gareth McCumskey answer. If you are planing to hook an existing event bus you could simply pass it's arn to eventBus key. Here is an example from serverless docs

- eventBridge:
    eventBus: arn:aws:events:us-east-1:12345:event-bus/custom- 
    private-events
    pattern:
      source:
        - custom.private

Another option is to use CloudFormation's intrinsic functions.