Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 57

Event-Driven Data Pipelines with Amazon EventBridge

Recommended resources

Hello! Welcome back to your preparation course for the AWS Certified Data Engineer - Associate exam.

In our last lesson, we fortified our Step Functions workflow with robust error handling and retry logic, ensuring it can gracefully manage the "unhappy paths." We now have a resilient, multi-step data pipeline. But a pipeline that requires manual execution isn't very useful in a real-world data platform. The next logical step is to automate it.

This lesson focuses on how to kick off your data pipelines automatically. As a Data Quality Engineer, you're familiar with ETL jobs that need to run at specific times or pipelines that must process new data as soon as it arrives. Amazon EventBridge is the AWS service that makes this automation possible.

By the end of this lesson, you will be able to configure Amazon EventBridge rules to trigger data pipelines based on schedules or events. We'll cover both time-based triggers (e.g., "run this pipeline every night at 2 AM") and event-based triggers (e.g., "run this pipeline whenever a new file is uploaded to our raw data S3 bucket").

What is Amazon EventBridge?

Before we configure any triggers, let's establish a clear understanding of what EventBridge is. At its core, EventBridge is a serverless event bus that enables you to build event-driven architectures. It acts as a central nervous system for your AWS applications, allowing different services to communicate with each other in a decoupled way.

This means that an "event producer" (like S3 or a scheduled timer) doesn't need to know anything about the "event consumer" (like our Step Functions workflow). It simply sends an event to the bus, and EventBridge takes care of routing it to the correct destination based on rules you define.

Amazon EventBridge: A Guide to Event-Driven Architecture

For a solid conceptual overview, please read the first part of the 'Amazon EventBridge: A Guide to Event-Driven Architecture' article from DataCamp. It explains what EventBridge is, its role in event-driven architecture, and its core components.

Read the sections 'What Is Amazon EventBridge?' and 'Core Components and Key Features of Amazon EventBridge'. Focus on understanding the key terms: Event Bus, Rules, and Targets. The comparison table with SNS and SQS is also useful for exam preparation.

As the article explains, there are two primary ways to trigger a rule, which perfectly align with our learning outcome for today:

  1. On a schedule: Triggering at a specific time or recurring interval.
  2. In response to an event: Triggering when something happens in your AWS environment.

Let's explore each of these in detail.


1. Triggering Data Pipelines on a Schedule

For recurring tasks like daily ETL loads, nightly batch processing, or hourly data quality checks, you need a time-based trigger. Amazon EventBridge Scheduler is the modern, flexible service designed for this purpose.

EventBridge Scheduler allows you to create, run, and manage scheduled tasks at scale. You can define either a recurring schedule or a one-time invocation for a future date.

Amazon EventBridge Scheduled Event Workflow
This diagram illustrates the flow of creating a scheduled trigger. You define a schedule (the 'when'), which follows a specific pattern (cron or rate). This triggers a target (the 'what', e.g., your Step Functions pipeline) and can include a specific payload (the 'with what data'). The process includes built-in resilience with retry policies.

How to Trigger an Event at a Specific Time with Amazon EventBridge Scheduler

The 'Be A Better Dev' channel has an excellent, concise walkthrough of EventBridge Scheduler. This video will guide you through the key configuration options.

Please watch the following segments: 2:02 - 3:11: This section explains the two main schedule patterns: recurring (cron-based and rate-based) and one-time. 6:01 - 7:51: Focus on how to select a target and, crucially, how to specify a JSON payload. This is vital for passing context to your data pipeline, such as a processing date. 7:51 - 8:47: Notice the settings for retry policies and Dead-Letter Queues (DLQs). This connects directly to our previous lesson on building resilient workflows.

Schedule Expressions: rate and cron

When configuring a recurring schedule, you have two options for the expression:

  • Rate expression: A simple way to define a regular frequency.
    • rate(1 hour)
    • rate(5 minutes)
  • Cron expression: Provides fine-grained control for more complex schedules. The format is minute hour day-of-month month day-of-week year.
    • cron(0 18 ? * MON-FRI *) - Runs at 6:00 PM UTC every weekday.
    • cron(15 2 * * ? *) - Runs at 2:15 AM UTC every day.

For the Data Engineer exam, you should be comfortable reading basic cron expressions.

Test your understanding!

You need to create a schedule that triggers a month-end financial processing pipeline at 5:00 AM UTC on the last day of every month. Which of the following cron expressions would you use?

  1. cron(0 5 * * L *)
  2. cron(5 0 L * ? *)
  3. cron(0 5 L * ? *)
Show answer

The correct answer is 3. cron(0 5 L * ? *).

  • 0 5 specifies 0 minutes and hour 5 (5:00 AM).
  • L in the day-of-month field means the last day of the month.
  • * in the month field means every month.
  • ? in the day-of-week field is used as a wildcard when you've already specified the day-of-month.

2. Triggering Data Pipelines Based on Events

Event-based triggers are at the heart of modern, responsive data architectures. Instead of waiting for a scheduled time, the pipeline runs as soon as the data is ready. A classic example in data engineering is triggering an ETL job when a new data file is uploaded to an S3 bucket.

This is achieved with an EventBridge Rule. A rule consists of two main parts:

  1. Event Pattern: A JSON object that acts as a filter. It examines incoming events and checks if they match the structure you've defined. If there's a match, the rule is triggered.
  2. Target: The AWS service that EventBridge should invoke. For our purposes, this would be our Step Functions state machine.
Event-Driven Data Pipeline with S3, EventBridge, and Glue
This architectural diagram shows a common event-driven pattern. A data upload to S3 generates an event, which is captured by an EventBridge rule. The rule's target is an AWS Glue workflow, initiating the data processing pipeline automatically.

Crafting Event Patterns

The power of event-driven triggers lies in the precision of the event pattern. You can filter events based on any field in the event's JSON payload.

For example, when you upload a file to S3, AWS generates an event that looks something like this (simplified):

{
  "version": "0",
  "id": "some-uuid",
  "detail-type": "Object Created",
  "source": "aws.s3",
  "account": "123456789012",
  "time": "2023-11-20T12:00:00Z",
  "region": "us-east-1",
  "resources": [
    "arn:aws:s3:::my-raw-data-bucket"
  ],
  "detail": {
    "version": "0",
    "bucket": {
      "name": "my-raw-data-bucket"
    },
    "object": {
      "key": "incoming/sales_data_2023-11-20.csv",
      "size": 1024,
      ...
    }
  }
}

To trigger a pipeline only for new CSV files in the incoming/ folder of this specific bucket, you would create a rule with this event pattern:

{
  "source": ["aws.s3"],
  "detail-type": ["Object Created"],
  "detail": {
    "bucket": {
      "name": ["my-raw-data-bucket"]
    },
    "object": {
      "key": [
        { "prefix": "incoming/" },
        { "suffix": ".csv" }
      ]
    }
  }
}

This pattern ensures your pipeline only runs for relevant events, preventing unnecessary executions and saving costs.

AWS ETL Workflow Orchestration with Glue, Athena, EventBridge, Lambda, and Step Functions – Hands-On

Let's see this in action. The 'FutureX Skills' video provides a hands-on demonstration of configuring an EventBridge rule to trigger a Step Functions workflow when a file is uploaded to S3.

Watch from 37:25 to 40:02. This section perfectly demonstrates the practical application of our learning outcome. Observe how the S3 upload event is defined as the trigger and the Step Functions state machine is set as the target.

Test your understanding!

Your data pipeline should only be triggered when a Glue Crawler successfully completes its run in your account. The source will be aws.glue and the detail-type will be Glue Crawler State Change. The detail object contains a state field with the value Succeeded.

Write the EventBridge event pattern to match this specific event.

Show answer
{
  "source": ["aws.glue"],
  "detail-type": ["Glue Crawler State Change"],
  "detail": {
    "state": ["Succeeded"]
  }
}

This pattern ensures that the rule only triggers on successful crawler runs, not on those that are starting, stopping, or have failed.


Conclusion

Today, you've learned how to automate your data pipelines, moving from manual execution to a fully event-driven or scheduled workflow using Amazon EventBridge. This is a fundamental skill for any data engineer working on AWS and a critical topic for the certification exam.

Key Takeaways:

  • Amazon EventBridge is the central service for automating workflows by routing events from sources to targets.
  • For time-based triggers, use EventBridge Scheduler, which supports simple rate expressions and complex cron expressions.
  • For action-based triggers, use an EventBridge Rule with a specific Event Pattern to filter for the exact events you want to process.
  • Common data engineering triggers include schedules for batch ETL and S3 Object Created events for new file processing.
  • The target for both schedulers and rules can be your Step Functions state machine, seamlessly integrating orchestration with automation.

Next Up:
In this lesson, we saw how to use EventBridge to react to an S3 event. However, S3 can also be configured to send notifications directly to a service like Lambda or SQS. When should you use a direct notification versus the more flexible routing through EventBridge? In our next lesson, we will compare these event-driven patterns to help you make the right architectural decisions for different scenarios.