Scheduling an AWS Lambda Function Using Amazon EventBridge Scheduler
Lab Steps
Introduction
Amazon EventBridge Scheduler allows you to create, run, and manage scheduled tasks at scale. With EventBridge Scheduler, you can create one-time or recurring schedules that run tasks on your behalf using various target APIs. Each schedule can be configured to run tasks within a specified time window, perform retries for failed tasks, and also send failed tasks into a dead letter queue for further investigation. Â
In this Lab Step, you will create a schedule using EventBridge Scheduler to invoke your Lambda function every minute.
Â
Instructions
1. In the AWS Management Console search bar, enter scheduler, and click the Amazon EventBridge Scheduler result under Services:
Â
2. Click Create schedule:
The schedule detail form will appear.
Â
3. Enter lab-schedule for the Schedule name, and ensure the default Schedule group is selected:
Placing your schedules into separate groups allows you to add tags and organize them by pattern or objective.
Note: Leave any unspecified fields as their defaults for the following instructions
Â
4. Configure the following for the Schedule pattern:
- Occurence: Select Recurring schedule
- Schedule type: Select Rate-based schedule
- Rate expression: Enter a Value of 1 and select a Unit of minutes from the drop-down menu
- Flexible time window: Select Off from the drop-down menu
The schedule will invoke your Lambda function every minute on a recurring schedule. A flexible time window is not necessary for this lab.
You won't be configuring a timeframe for this schedule. The schedule will start the recurring invocation of the target Lambda function when the schedule is created.
Â
5. Click Next:
Â
6. Ensure Templated targets option is selected, then select the AWS Lambda Invoke target API:
Â
7. In the Invoke section of the page, select lab-function from the Lambda function drop-down menu, and click Next:
Â
8. On the Settings page, scroll down for the Retry policy and dead-letter queue section and deselect the Retry policy option:
EventBridge scheduler will retry any failed Lambda invocations for up to 24 hours by default. This is helpful when dealing with an unresponsive target as the scheduler can be configured to retry until the target is operational again.
Â
9. Scroll down to the Permissions section and configure the following:
- Execution role: Select Use existing role
- Select an existing role: Select the scheduler_role from the drop-down menu
The scheduler_role is an IAM Role that was preconfigured for you at the start of this lab. The role contains a policy that grants this schedule permission to use the lambda:InvokeFunction action on your Lambda function.
Â
10. Click Next, then Create schedule on the review page:
The following notification will appear to inform you that the schedule has been created:
You have configured this schedule to invoke your Lambda function every minute.
Â
Summary
In this Lab Step, you created an EventBridge schedule that invokes your Lambda function every minute.
Check if the EventBridge schedule has been created for this lab