Lesson 3 of 3 Amazon SQS, SNS and EventBridge

Routing Events with Amazon EventBridge

This lesson explains how EventBridge, a serverless event bus, routes events between AWS services, SaaS applications and your own applications.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe the default, custom and partner event buses.
  • Describe how rules route events to targets.
  • Describe EventBridge Scheduler and Pipes.
  • Choose between EventBridge and SNS.

Event buses

EventBridge routes events through buses, and rules on each bus send matching events to targets. The default bus in every account receives events from AWS services, such as EC2 state changes, AWS Health events, GuardDuty findings and, when enabled on a bucket, S3 object events, so a rule can react to them without polling.

A custom bus receives an application's own events, such as an order being placed, which keeps them separate from AWS events and lets other accounts send to it. A partner bus receives events from software-as-a-service providers, such as Zendesk, Datadog or Shopify, so their events can trigger AWS workflows directly. The following table summarises the bus types.

BusReceives
DefaultAWS service events: EC2 state changes, AWS Health, GuardDuty findings, S3 (when enabled)
CustomYour applications' events
PartnerSaaS events: Zendesk, Datadog, Shopify…

Rules and targets

Amazon EventBridge routes events with rules that match JSON event patterns and send matching events to targets: Lambda functions, SQS queues, SNS topics, Step Functions workflows, Kinesis streams, ECS tasks, API destinations or event buses in other accounts. Rules can transform the event before delivery, and failed deliveries are retried and can be sent to a dead-letter queue.

Forwarding events from every account to a central bus in a security or operations account collects events, such as GuardDuty findings or EC2 state changes, in one place. API destinations call third-party HTTP APIs with authentication and rate limiting, with no Lambda function needed. Archive and replay stores events and reprocesses them later, and the schema registry documents the structure of events.

The following diagram shows events flowing from sources through rules to targets.

How EventBridge routes events. AWS services, applications and SaaS partners send events to an event bus. Rules match JSON event patterns, can transform each event and send it to targets such as Lambda, SQS, Step Functions, an API destination or a bus in another account. Failed deliveries are retried and can go to a dead-letter queue.
One event can match several rules, and each rule can have several targets.

Scheduler and Pipes

Two EventBridge features work without rules on a bus. EventBridge Scheduler invokes a target at a set time, once or repeatedly with a cron or rate expression, and can manage millions of schedules, such as one reminder per customer, each with its own retry policy. It replaces cron jobs on servers. EventBridge Pipes connects a source, such as an SQS queue, a Kinesis stream or a DynamoDB stream, to a target, with optional filtering and enrichment along the way, so no Lambda function is needed just to move data. The following table summarises the two features.

FeatureUse
EventBridge SchedulerMillions of one-time or cron schedules invoking targets
EventBridge PipesSource (SQS, Kinesis, DynamoDB Streams) to target with filtering and enrichment, no code

The following diagram shows the stages of a pipe, with Scheduler below.

EventBridge Pipes and Scheduler. A pipe connects a source such as an SQS queue, Kinesis stream or DynamoDB stream to a target, with optional filtering and enrichment along the way, so no Lambda function is needed just to move data. Scheduler invokes targets on one-time or cron schedules, up to millions of them.
Filtering and enrichment are optional; a pipe can also move every event unchanged.
Scenario questions

EventBridge features

Exam skills 2.1.3 · 2.1.5

Choose the EventBridge feature for each requirement.

Log in to try this activity Interactive activities are free with an account.

EventBridge or SNS

EventBridge and SNS can both deliver one message to several targets, and the choice depends on the requirement. EventBridge is the better choice when routing depends on the content of events, because rules can match any field, when events come from AWS services or SaaS applications, or when events must be archived and replayed. SNS is the better choice for very high fan-out throughput to many subscribers and for pushing notifications to people by email, SMS or mobile push. The following table summarises the strengths of each.

EventBridgeSNS
Rich content-based routing, SaaS integration, replayHigher fan-out throughput; push to email, SMS and mobile
Sort into groups

EventBridge or SNS?

Exam skills 2.1.3

Decide which service fits each requirement.

Log in to try this activity Interactive activities are free with an account.
Worked example

Replacing cron servers and polling

EventBridge can replace scheduled servers and polling scripts with managed, event-driven alternatives. The following table pairs several older approaches with their EventBridge replacements.

Old approachEventBridge replacement
An EC2 instance running cron jobs to start nightly reportsEventBridge Scheduler invoking Lambda
A script polling for EC2 instances being terminatedA rule on EC2 state-change events
Custom code receiving webhooks from a SaaS providerA partner event source on EventBridge
Code reading DynamoDB Streams to forward changes to an APIEventBridge Pipes with filtering and enrichment

Each change removes a server or custom code. EventBridge's content-based rules, many target types and support for AWS, SaaS and custom events make it the default choice for event-driven architectures.

Check yourself

Which service receives events from SaaS applications, such as Zendesk or Datadog, without custom code?

Show answer

Amazon EventBridge, through partner event sources and their event buses.

Exam Tips

Remember for the exam

  • To react to AWS service events, such as an instance state change or a GuardDuty finding, use an EventBridge rule.
  • To integrate events from SaaS applications, use an EventBridge partner event bus.
  • To run a task on a cron schedule without servers, use EventBridge Scheduler.
  • To collect events from all accounts centrally, use rules that forward to a central event bus.
  • To call a SaaS HTTP API from an event without code, use an EventBridge API destination.