AWS CloudWatch

CloudWatch Events EventBridge Event Buses

Demo Hands on with AWS Eventbridge schedulers

In this guide, you’ll learn how to use AWS EventBridge to schedule AWS Lambda function invocations. We’ll walk through creating a simple “Hello World” Lambda, setting up a recurring schedule in EventBridge, monitoring invocations, and exploring real-world scenarios.

Note

Scheduling functions with EventBridge may incur additional charges. Check the EventBridge pricing before you begin.

Prerequisites

  • An AWS account with permissions for Lambda and EventBridge
  • Basic familiarity with the AWS Management Console

Step 1: Create a Lambda Function

  1. Sign in to the AWS Management Console.
  2. Navigate to AWS Lambda > Functions > Create function.
  3. Choose Blueprint, search for “Hello World,” and select it.
  4. Enter a name, e.g., my_lambda.
  5. Select Node.js 18.x (or Python 3.x if you prefer).
  6. Keep all other settings as default and click Create function.

The image shows the AWS Lambda console where a user is creating a new function using a blueprint. The function is named "my_lambda" with Node.js 18.x as the runtime.


Step 2: Add the Function Code

  1. In the inline editor, replace the default handler with the following Python code:
import json

def lambda_handler(event, context):
    print("loading function")
    return json.dumps(event, indent=2)
  1. Click Deploy.

By default, there is no trigger attached. Next, we’ll configure EventBridge.


Step 3: Create an EventBridge Schedule

  1. Open the Amazon EventBridge console.
  2. In the left pane, choose Schedules > Create schedule.
  3. Enter a name (e.g., every-2-minutes) and select Recurring schedule.
  4. Under Schedule type, pick Rate-based and set it to Every 2 minutes.
    • You can also use a cron expression under Cron-based if needed.
  5. Click Next, disable Enabled, and click Next again.

The image shows a screenshot of the Amazon EventBridge Scheduler interface, where a recurring rate-based schedule is being set to run every 2 minutes. The interface includes options for time zone and daylight saving adjustments.


Step 4: Configure the Schedule Target

  1. For Target, choose AWS service > Lambda function.
  2. Select your my_lambda function from the dropdown (hit the refresh icon if it doesn’t appear).
  3. (Optional) Add a custom JSON payload in the Input section.
  4. Click Next, then Create schedule.
  5. Finally, enable the schedule to start invoking your function every 2 minutes.

The image shows an Amazon Web Services (AWS) EventBridge Scheduler interface where a user is selecting a target API for a schedule. Various AWS services like CodeBuild, Lambda, and SNS are listed as options.

The image shows an AWS EventBridge Scheduler interface where a Lambda function named "my_lambda" is being configured with options to create a new Lambda function and input a JSON payload.


Step 5: Monitor Invocations

  1. Go back to the Lambda console and open your my_lambda function.
  2. Select the Monitor tab.
  3. Adjust the time range to Last 30 minutes (or 15 minutes).
  4. You should see invocations every 2 minutes along with logs and metrics.

The image shows an AWS Lambda monitoring dashboard with CloudWatch metrics, including graphs for invocations, duration, error count, success rate, throttles, total concurrent executions, and recursive invocations dropped.

Scroll down to view individual invocation timestamps and durations.


Common Use Cases

Use CaseDescriptionExample
Periodic Health ChecksRun database or API checks at regular intervalsLambda polls an RDS instance, logs health status
Scheduled NotificationsSend reminders or alerts via SNSLambda composes a message and publishes to an SNS topic
Automated ReportsGenerate and distribute reports to stakeholdersLambda fetches data from S3, formats a PDF, emails via SNS

For instance, you could have EventBridge trigger a Lambda that loads a PDF of DevOps headlines from S3 and pushes it to an SNS topic for subscriber email delivery.

The image shows the AWS Lambda console with details of a function named "my_lambda," including options for monitoring, configuration, and CloudWatch metrics.


Cleanup

To avoid ongoing charges:

  1. Delete the my_lambda function in AWS Lambda.
  2. Remove your schedule under EventBridge > Schedules.

Warning

Be sure to clean up both Lambda functions and EventBridge schedules to prevent unexpected costs.

The image shows the Amazon EventBridge Scheduler interface, highlighting features like templated targets, universal targets, flexible time windows, and retries. It includes options to create and manage schedules within the AWS console.


Watch Video

Watch video content

Previous
Event Patterns Scheduled Events and Pipes