In this short article I will talk about how you can use AWS EventBridge to trigger Lambda functions on a schedule or periodically. Here I will focus more on the EventBridge functionality rather than Lambda.
Let start with a simple lambda function. I will just create a hello world lambda function which will print a some thing into the logs.
Then in the function overview section you can click the + Add trigger option to configure how trigger this lambda.
In the next screen, it will throw to bunch of options you can use as the triggers for Lambda; but search for EventBridge and select that.
Next screen you will ask to configure the EventBridge rule to trigger your Lambda. In my case I want my Lambda function to run every hour periodically. So here I will create a new Rule that will trigger my Lambda function every hour.
Rate Expressions
A rate expression starts when you create the scheduled event rule, and then runs on its defined schedule.
Rate expressions have two required fields. Fields are separated by white space.
rate(value unit)
value: A positive number.
unit: The unit of time. Different units are required for values of 1, such as minute
, and values over 1, such as minutes
.
Valid values: minute
| minutes
| hour
| hours
| day
| days
Cron Expressions
Cron expressions have six required fields, which are separated by white space.
cron(fields)
Some Example of the Cron Expression as below.
There are many other use cases of EventBridge but one popular one would be we can use EventBridge to execute Step Funcitons as well. You can see an Actions in the top right hand corner of you Step Functions project. Click that and then select Create EventBridge rule. That will get you to the above shown (Configure EventBridge) EventBride configuration page.
References: https://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html
Top comments (1)
Great write-up. We also recently published an article on how to bridge Backend and Data Engineering teams using Event Driven Architecture - packagemain.tech/p/bridging-backen...