How to schedule AWS Lambda functions using EventBridge

Photo by AltumCode on Unsplash

How to schedule AWS Lambda functions using EventBridge

AWS EventBridge is a serverless event bus service that facilitates building application architectures driven by events. It enables you to set up routes between your source events and targeted AWS services.

Let's break down AWS EventBridge and its integration with AWS Lambda functions.

Components of AWS EventBridge:

  1. Event Buses: A conduit to receive events. You can use the default event bus or create custom ones.

  2. Events: An event is a signal that a system's state has changed. In AWS, these could come from AWS services, integrated SaaS applications, or custom sources.

  3. Rules: Determine how events on an event bus are routed to targets. A rule matches incoming events and routes them to targets for processing.

  4. Targets: An AWS service or resource that acts on matched events. AWS Lambda is one of the supported targets.

How it integrates with AWS Lambda:

  1. Source: Start with an event source. This could be any AWS service like Amazon S3 (e.g., when a new object is added to a bucket) or custom applications sending events to the event bus.

  2. Event Bus: The event from the source is sent to the EventBridge event bus.

  3. Rules: Within EventBridge, you set up rules to determine how to handle and where to send these incoming events. A rule listens for specific events defined by the event pattern or schedule.

  4. Targeting Lambda: If a rule's conditions are met (i.e., an incoming event matches the criteria specified in the rule), EventBridge can trigger one or more target actions. One such action can be invoking an AWS Lambda function. So, you can set AWS Lambda as a target for matched events.

  5. Lambda Execution: Once AWS Lambda is invoked, it runs your function code securely within an execution role, which grants the function permissions to use other AWS services.

Steps to integrate EventBridge with Lambda:

  1. Create a Lambda function: This will contain the logic you want to execute when a specific event occurs.

  2. Define an EventBridge Rule:

    • Navigate to the EventBridge console.

    • Create a new rule.

    • Define the event pattern or schedule that will trigger this rule.

  3. Set Lambda as a Target:

    • In the targets section of the rule, select "Lambda function".

    • Choose the Lambda function you created in step 1.

  4. Test the Integration: Send events to the event bus that match your rule's criteria. This should trigger your Lambda function.

  5. Monitor: Use services like Amazon CloudWatch to monitor the Lambda invocations and view logs for debugging and tracking.


  1. Decoupling: EventBridge facilitates decoupling between services, making systems more modular and easier to maintain and scale.

  2. Flexibility: EventBridge can handle events from a vast array of AWS services, integrated SaaS applications, and custom sources, offering a lot of flexibility in terms of event sources.

  3. Scalability: Both AWS Lambda and EventBridge are serverless, so they scale automatically with the number of incoming events.

AWS EventBridge's integration with AWS Lambda provides a powerful mechanism for event-driven architectures, allowing for efficient, real-time processing and reaction to system changes.

Use Cases:

The integration of EventBridge and AWS Lambda is particularly useful for crafting event-driven architectures. Here are several common use cases:

  1. Application Integrations:

    • Microservices Coordination: When microservices architectures are used, EventBridge can relay events from one service to another. Lambda functions can be triggered to process data, transform it, or trigger another microservice.

    • SaaS Application Integration: Integrate with third-party SaaS applications like Datadog, Auth0, or Zendesk. When an event occurs in these applications (like a new ticket in Zendesk), a Lambda function could be triggered to process or react to that event.

  2. Operational Tasks:

    • Automated Backup: Trigger Lambda to initiate backups of databases or other services based on scheduled events.

    • Cleanup Tasks: Automatically delete unused resources, such as old EBS snapshots or unused EC2 instances based on specific triggers or schedules.

  3. Real-time Analytics and Monitoring:

    • Log Processing: Ingest logs into EventBridge and use Lambda to process, analyze, and store them in databases or send to monitoring tools.

    • Real-time Alerts: Trigger Lambda functions to send alerts or notifications when specific operational events occur, like errors or thresholds being reached.

  4. Workflow Automation:

    • Order Processing: When a new order is placed in an e-commerce application, an event is sent to EventBridge. A Lambda function could then handle various stages of the order lifecycle, like inventory check, payment processing, or sending notifications.
  5. IoT (Internet of Things):

    • Device Data Processing: IoT devices can send data to AWS IoT Core, which then routes the data to EventBridge. Lambda can process this data, for instance, to update device shadows, store readings, or trigger alarms based on device metrics.
  6. Custom Application Events:

    • User Sign-up: When a user signs up on a platform, an event can be emitted. Lambda can then process this event, sending a welcome email or populating default user settings.
  7. Security and Compliance:

    • Automated Remediation: If a non-compliant resource is detected (like an S3 bucket being made public), an event can be sent. A Lambda function could then automatically modify the bucket's permissions to make it private again.

    • Suspicious Activity Alerts: When suspicious or anomalous activities are detected, Lambda functions can be triggered to send alerts, take protective actions, or integrate with other security tools.

  8. Distributed Tracing and Auditing:

    • Audit Trail: Create an audit trail by capturing events related to resource changes, user activities, etc. Lambda can process these events and store them in a structured manner for future reference or analysis.
  9. System Health Monitoring:

    • Health Checks: Trigger Lambda functions at regular intervals to perform health checks on services and applications. If anomalies are found, corrective actions can be initiated, or notifications can be sent.
  10. Content and Data Management:

  • Content Moderation: When users upload content, an event can be emitted. Lambda can be used to trigger moderation tools or processes to ensure the content adheres to guidelines before it's publicly accessible.

The beauty of the EventBridge and Lambda integration lies in its versatility. The above use cases are just the tip of the iceberg. With custom events and the flexibility to define specific reactions to these events, the possibilities are vast.

Tutorial: Schedule AWS Lambda functions using EventBridge

You can set up a rule to run an AWS Lambda function on a schedule. This tutorial shows how to use the AWS Management Console or the AWS CLI to create the rule.

For schedules, EventBridge doesn't provide second-level precision in schedule expressions. The finest resolution using a cron expression is one minute. Due to the distributed nature of EventBridge and the target services, there can be a delay of several seconds between the time the scheduled rule is triggered and the time the target service runs the target resource.

Step 1: Create a Lambda function

Create a Lambda function to log the scheduled events.

To create a Lambda function
  1. Open the AWS Lambda console at

  2. Choose Create function.

  3. Choose Author from scratch.

  4. Enter a name and description for the Lambda function. For example, name the function LogScheduledEvent.

  5. Change Runtime to Node.js 14.x and choose Create function.

  6. On the Code tab of the function page, double-click index.js.

  7. Replace the existing code with the following code.

     'use strict';
     exports.handler = (event, context, callback) => {
         console.log('Received event:', JSON.stringify(event, null, 2));
         callback(null, 'Finished');
  8. Choose Deploy.

Step 2: Create a Rule

Create a rule to run the Lambda function you created in step 1 on a schedule.

You can use either the console or the AWS CLI to create the rule. To use the AWS CLI, you first grant the rule permission to invoke your Lambda function. Then you can create the rule and add the Lambda function as a target.

To create a rule (console)
  1. Open the Amazon EventBridge console at

  2. In the navigation pane, choose Rules.

  3. Choose Create rule.

  4. Enter a name and description for the rule.

    A rule can't have the same name as another rule in the same Region and on the same event bus.

  5. For Event bus, choose the event bus that you want to associate with this rule. If you want this rule to match events that come from your account, select AWS default event bus. When an AWS service in your account emits an event, it always goes to your account’s default event bus.

  6. For Rule type, choose Schedule.

  7. For Schedule pattern, choose A schedule that runs at a regular rate, such as every 10 minutes. and enter 5 and choose Minutes from the drop-down list.

  8. Choose Next.

  9. For Target types, choose AWS service.

  10. For Select a target, choose Lambda function from the drop-down list.

  11. For Function, select the Lambda function that you created in the Step 1: Create a Lambda function section. In this example, select LogScheduledEvent.

  12. Choose Next.

  13. Choose Next.

  14. Review the details of the rule and choose Create rule.

Step 3: Verify the rule

Wait at least five minutes after completing step 2, and then you can verify that your Lambda function was invoked.

View the output from your Lambda function
  1. Open the CloudWatch console at

  2. In the navigation pane, choose Logs.

  3. Select the name of the log group for your Lambda function (/aws/lambda/function-name).

  4. Select the name of the log stream to view the data provided by the function for the instance that you launched.


  1. I am receiving a reference error in AWS lambda

  2. Tutorial: Schedule AWS Lambda functions using EventBridge

  3. Amazon EventBridge

  4. Serverless Land