Reading25 min read·Module 2

Amazon EventBridge

Key concepts

  • Event buses

  • Event rules and patterns

  • Schema registry

  • Cross-account events

  • Archive and replay

Overview

Amazon EventBridge is a serverless event bus service that enables you to build event-driven architectures by routing events from AWS services, custom applications, and SaaS partners to target services. EventBridge provides powerful event pattern matching, cross-account delivery, and schema discovery capabilities.

Understanding EventBridge is important for the SAA-C03 exam because it's the modern approach to event-driven architectures in AWS, replacing CloudWatch Events with enhanced capabilities. You must know when to use EventBridge vs SNS vs SQS, how to configure event rules and patterns, and how to design cross-account event architectures.

Event-Driven Architecture Hub

EventBridge is the recommended service for building event-driven architectures when you need complex event pattern matching, SaaS partner integration, scheduled events (cron), or cross-account event sharing.

Exam Tip

Focus on event buses (default, custom, partner), event rules with pattern matching, cross-account event delivery, archive and replay for debugging, and comparing EventBridge vs SNS vs SQS use cases.


Key Concepts

EventBridge Architecture

EventBridge Architecture Overview
Figure 1: EventBridge routes events from sources through rules to targets

Event Bus

An event bus receives events from various sources. There are three types:

  • Default event bus: Automatically receives events from AWS services
  • Custom event bus: Receives events from your applications
  • Partner event bus: Receives events from SaaS partners (Zendesk, Datadog, Auth0, etc.)

Rules and Targets

Rules define which events to match using event patterns or schedules. Each rule can have up to 5 targets. Targets are AWS services that receive matched events: Lambda, SQS, SNS, Step Functions, Kinesis, API Gateway, and more.

Event Structure

JSONEventBridge Event Format
{
  "version": "0",
  "id": "12345678-1234-1234-1234-123456789012",
  "detail-type": "EC2 Instance State-change Notification",
  "source": "aws.ec2",
  "account": "123456789012",
  "time": "2025-01-18T12:00:00Z",
  "region": "us-east-1",
  "resources": [
    "arn:aws:ec2:us-east-1:123456789012:instance/i-1234567890abcdef0"
  ],
  "detail": {
    "instance-id": "i-1234567890abcdef0",
    "state": "stopped"
  }
}

Event Patterns

Event Pattern Matching

Event patterns define which events a rule matches. Patterns match event fields using exact match, prefix match, numeric comparisons, IP address matching, and exists/not exists checks. Only matched events are delivered to targets.

JSONEvent Pattern Examples
// Match EC2 instance state changes to "stopped" or "terminated"
{
  "source": ["aws.ec2"],
  "detail-type": ["EC2 Instance State-change Notification"],
  "detail": {
    "state": ["stopped", "terminated"]
  }
}

// Match events from specific account with prefix
{
  "source": [{"prefix": "myapp."}],
  "account": ["123456789012"]
}

// Match numeric range (order value > 1000)
{
  "source": ["myapp.orders"],
  "detail": {
    "value": [{"numeric": [">", 1000]}]
  }
}

// Match when field exists
{
  "detail": {
    "error-code": [{"exists": true}]
  }
}

Rule Types

EventBridge Rule Types

Rule TypeTriggerUse Case
Event PatternMatches incoming eventsReact to AWS/app events
Schedule (rate)Fixed interval (rate(5 minutes))Periodic tasks
Schedule (cron)Cron expressionSpecific times (daily reports)
TEXTSchedule Expressions
Rate Expressions:
├── rate(1 minute)    - Every minute
├── rate(5 minutes)   - Every 5 minutes
├── rate(1 hour)      - Every hour
└── rate(1 day)       - Every day

Cron Expressions: cron(minutes hours day-of-month month day-of-week year)
├── cron(0 12 * * ? *)        - 12:00 PM UTC daily
├── cron(0 8 ? * MON-FRI *)   - 8:00 AM weekdays
├── cron(0/15 * * * ? *)      - Every 15 minutes
└── cron(0 18 ? * MON *)      - 6:00 PM every Monday

EventBridge Services

Schema Registry

EventBridge Schema Registry
Figure 2: Schema Registry discovers and stores event structures for code generation

Schema Registry

Schema Registry automatically discovers and stores event schemas from your event buses. Schemas describe the structure of events, enabling IDE code completion and validation. EventBridge can generate code bindings for Java, Python, and TypeScript.

TEXTSchema Registry Benefits
Schema Registry Features:
├── Auto-Discovery
│   ├── Discovers schemas from events on the bus
│   └── Creates versioned schema definitions
│
├── Code Bindings
│   ├── Generate typed classes (Java, Python, TypeScript)
│   ├── Download from console or CLI
│   └── Use with AWS Toolkit for IDEs
│
└── Cross-Account Discovery
    ├── Share schemas across accounts
    └── Centralize event documentation

Archive and Replay

Event Archive and Replay

Archives store events for a configurable retention period. Replay allows you to resend archived events to an event bus for debugging, testing, or recovery. Events are not guaranteed to replay in original order.

Archive and Replay

FeatureDescriptionUse Case
ArchiveStore events with retention periodCompliance, debugging
ReplayResend archived events to busTest fixes, recover from errors
Partial ReplayReplay events from time rangeTargeted debugging
TEXTArchive and Replay Flow
1. Create Archive
   └── Specify event bus and retention period
       └── Optional: Filter events with pattern

2. Events Flow
   └── Events matching pattern are archived
       └── Stored for retention period (days)

3. Replay Events
   ├── Specify archive and time range
   ├── Select rules to replay to (or all)
   └── Events re-delivered to targets

Important Notes:
├── Events NOT replayed in original order
├── Add timestamps to events for ordering
├── Replay generates new event IDs
└── Targets must be idempotent

EventBridge Pipes

EventBridge Pipes

Pipes provide point-to-point integrations between event sources and targets with optional filtering, enrichment, and transformation. Pipes connect directly without using an event bus, simplifying 1:1 integrations.

TEXTEventBridge Pipes Architecture
Source → Filter → Enrichment → Target

Sources:
├── DynamoDB Streams
├── Kinesis Data Streams
├── Amazon MQ
├── Amazon MSK
├── Self-managed Apache Kafka
└── Amazon SQS

Optional Steps:
├── Filter: Match event patterns
├── Enrich: Call Lambda/Step Functions/API Gateway
└── Transform: Reshape event before delivery

Targets:
├── Lambda, Step Functions
├── SQS, SNS, Kinesis
├── EventBridge bus
├── API Gateway, API destinations
└── Many more AWS services

EventBridge Scheduler

EventBridge Scheduler

Scheduler is a serverless scheduler for creating, executing, and managing scheduled tasks at scale. Unlike EventBridge rules with schedules, Scheduler supports one-time schedules and can invoke targets in other accounts.

Scheduler vs Rule Schedules

FeatureEventBridge RulesEventBridge Scheduler
One-time schedulesNoYes
Recurring schedulesYesYes
Scale~300 rules per busMillions of schedules
Cross-account targetsNoYes
Time zonesUTC onlyAll time zones

API Destinations

API Destinations

API destinations allow EventBridge to send events to HTTP endpoints outside AWS. Configure authentication (Basic, OAuth, API Key), rate limiting, and input transformation to integrate with external APIs and SaaS applications.

TEXTAPI Destination Configuration
API Destination Components:
├── Connection
│   ├── Authorization: Basic, OAuth, API Key
│   └── Shared across destinations
│
├── API Destination
│   ├── HTTP endpoint URL
│   ├── HTTP method (POST, PUT, etc.)
│   └── Invocation rate limit (per second)
│
└── Rule/Pipe Target
    ├── Input transformation
    └── Dead-letter queue for failures

Timeouts and Limits:
├── Request timeout: 5 seconds max
├── Retry: Up to 24 hours, 185 attempts
└── Rate limiting: 300 invocations/second max

Cross-Account Events

EventBridge Cross-Account Events
Figure 3: Cross-account event delivery centralizes events from multiple accounts

Cross-Account Event Delivery

EventBridge supports sending events across accounts using resource-based policies. The receiving account must grant permission to the sending account. Common pattern: centralize events from multiple accounts into a single monitoring account.

JSONCross-Account Configuration
// Resource policy on receiving account's event bus
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "AllowAccountToPutEvents",
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::111122223333:root"
      },
      "Action": "events:PutEvents",
      "Resource": "arn:aws:events:us-east-1:444455556666:event-bus/central-bus"
    }
  ]
}
TEXTCross-Account Architecture
Account A (Production)                Account B (Monitoring)
┌─────────────────────┐              ┌──────────────────────┐
│  Default Event Bus  │              │   Central Event Bus  │
│         │           │              │          │           │
│    [Rule: Forward]  │──────────────│►    [Rule: Alert]    │
│         │           │  PutEvents   │          │           │
│    (all events)     │              │      [SNS Topic]     │
└─────────────────────┘              └──────────────────────┘

Account C (Development)
┌─────────────────────┐
│  Default Event Bus  │
│         │           │
│    [Rule: Forward]  │──────────────────────────┘
└─────────────────────┘

EventBridge vs SNS vs SQS

When to Use Each Service

RequirementBest ServiceWhy
Point-to-point queuingSQSBuffering, decoupling
Fan-out to multiple subscribersSNSPush-based pub/sub
Complex event pattern matchingEventBridgeRich filtering syntax
SaaS partner integrationEventBridgeBuilt-in partner buses
Scheduled/cron jobsEventBridgeNative scheduling support
SMS/Email/Push notificationsSNSDirect notification protocols
Message retention/replayEventBridge (archive)Built-in archive and replay
Cross-account eventsEventBridgeResource-based policies
TEXTService Selection Decision Tree
Do you need to integrate with SaaS partners?
├── Yes → EventBridge (partner event sources)
└── No ↓

Do you need complex event pattern matching?
├── Yes → EventBridge (content-based filtering)
└── No ↓

Do you need scheduled/cron jobs?
├── Yes → EventBridge (Scheduler or rule schedules)
└── No ↓

Do you need SMS/Email/Push notifications?
├── Yes → SNS (notification protocols)
└── No ↓

Do you need fan-out to multiple consumers?
├── Yes → SNS (or EventBridge with multiple targets)
└── No ↓

Do you need message buffering/persistence?
├── Yes → SQS (message retention up to 14 days)
└── No → Consider EventBridge for AWS service events

Input Transformation

Input Transformation

Input transformers customize the event payload before delivery to targets. Use input paths to extract values from the event, then use an input template to construct the transformed payload.

JSONInput Transformation Example
// Original Event
{
  "detail-type": "EC2 Instance State-change Notification",
  "source": "aws.ec2",
  "detail": {
    "instance-id": "i-1234567890abcdef0",
    "state": "stopped"
  }
}

// Input Path (extract values)
{
  "instance": "$.detail.instance-id",
  "status": "$.detail.state"
}

// Input Template (construct payload)
{
  "message": "Instance <instance> is now <status>",
  "timestamp": "<aws.events.event.ingestion-time>"
}

// Result sent to target
{
  "message": "Instance i-1234567890abcdef0 is now stopped",
  "timestamp": "2025-01-18T12:00:00.000Z"
}

Best Practices

Architecture Best Practices

TEXTEventBridge Architecture Patterns
1. Use Custom Event Buses for Application Events
   ├── Separate from AWS service events
   ├── Easier access control
   └── Cleaner event organization

2. Implement Dead-Letter Queues
   ├── Capture failed deliveries
   ├── SQS queue as DLQ
   └── Monitor and alert on DLQ messages

3. Use Schema Registry
   ├── Document event structures
   ├── Generate typed code
   └── Version schemas for compatibility

4. Archive Events for Compliance
   ├── Configure retention period
   ├── Use event patterns to filter
   └── Enable replay for debugging

5. Design Idempotent Targets
   ├── Events may be delivered multiple times
   ├── Replay doesn't guarantee order
   └── Use event IDs for deduplication

Security Best Practices

Security Considerations

Use resource-based policies to control which accounts can put events to your bus.

Encrypt sensitive data in event payloads using client-side encryption.

Use VPC endpoints for EventBridge in private subnets.

Implement least privilege for rules and targets using IAM roles.


Common Exam Scenarios

Exam Scenarios

ScenarioSolutionWhy
React to EC2 state changesEventBridge rule on default busAWS events go to default bus
Trigger Lambda on scheduleEventBridge rule with cron expressionNative scheduling support
Integrate with Zendesk eventsEventBridge partner event sourceBuilt-in SaaS integration
Centralize events from multiple accountsCross-account EventBridgeResource-based policies
Debug event processing issuesArchive and replay eventsReplay to test fixes
Send events to external APIAPI destinationsHTTP endpoint integration
Match events by contentEvent pattern with detail filtersContent-based filtering
Point-to-point DynamoDB to LambdaEventBridge PipesDirect integration without bus

Common Pitfalls

Pitfall 1: Not Using Dead-Letter Queues

Mistake: Not configuring DLQs for rule targets.

Why it fails: Failed deliveries are lost; no visibility into failures.

Correct Approach: Configure SQS DLQ for each rule; monitor DLQ depth.

Pitfall 2: Assuming Event Order in Replay

Mistake: Assuming replayed events arrive in original order.

Why it fails: Archive replay does not guarantee ordering.

Correct Approach: Include timestamps in events; design targets to handle out-of-order.

Pitfall 3: Using Default Bus for Application Events

Mistake: Sending custom application events to the default bus.

Why it fails: Mixed with AWS service events; harder to manage access control.

Correct Approach: Create custom event buses for application events.

Pitfall 4: Not Handling API Destination Timeouts

Mistake: Not accounting for the 5-second timeout limit.

Why it fails: Slow external APIs cause delivery failures.

Correct Approach: Ensure endpoints respond quickly; use DLQ for retries.

Pitfall 5: Overly Broad Event Patterns

Mistake: Creating rules that match too many events.

Why it fails: Increased costs and target invocations.

Correct Approach: Use specific patterns; filter in rule, not in target.



Quick Reference

EventBridge Limits

Key EventBridge Limits

ResourceDefault Limit
Rules per event bus300
Targets per rule5
Event buses per account100
Event size256 KB
PutEvents batch size10 events
Invocations per second (API dest)300

Pricing Summary

TEXTEventBridge Pricing (US East)
Events:
├── Custom events: $1.00 per million
├── AWS service events: Free
├── Cross-account: $1.00 per million
└── Partner events: $0.05 per million

Scheduler:
├── Standard schedules: $1.00 per million invocations
└── One-time schedules: Free

Archive & Replay:
├── Archive storage: $0.023 per GB-month
├── Archive processing: $0.10 per GB
└── Replay: $1.00 per million events

API Destinations:
└── Invocations: $0.20 per million

Common CLI Commands

SHEventBridge CLI Commands
# Create custom event bus
aws events create-event-bus --name my-app-bus

# Create rule with event pattern
aws events put-rule \
  --name "ec2-stopped-rule" \
  --event-bus-name "default" \
  --event-pattern '{"source":["aws.ec2"],"detail-type":["EC2 Instance State-change Notification"],"detail":{"state":["stopped"]}}'

# Create scheduled rule (every 5 minutes)
aws events put-rule \
  --name "every-5-min" \
  --schedule-expression "rate(5 minutes)"

# Add Lambda target to rule
aws events put-targets \
  --rule "ec2-stopped-rule" \
  --targets "Id"="1","Arn"="arn:aws:lambda:us-east-1:123456789012:function:MyFunction"

# Put custom event
aws events put-events \
  --entries '[{"Source":"myapp","DetailType":"OrderCreated","Detail":"{\"orderId\":\"12345\"}","EventBusName":"my-app-bus"}]'

# Create archive
aws events create-archive \
  --archive-name "my-archive" \
  --event-source-arn "arn:aws:events:us-east-1:123456789012:event-bus/default" \
  --retention-days 30

Test Your Knowledge

Q

A company wants to trigger a Lambda function every weekday at 8:00 AM UTC. Which EventBridge configuration should they use?

AEvent pattern rule matching CloudWatch scheduled events
BRule with schedule expression: rate(1 day)
CRule with schedule expression: cron(0 8 ? * MON-FRI *)
DEventBridge Pipes with schedule source
Q

A solutions architect needs to receive events from Zendesk into AWS for processing. What is the MOST efficient approach?

ACreate a Lambda function to poll Zendesk API
BUse API Gateway to receive webhooks from Zendesk
CConfigure EventBridge partner event source for Zendesk
DSet up SQS queue with Zendesk publishing messages
Q

An application needs to send events to an external REST API. The API sometimes takes 10 seconds to respond. What should the architect consider?

AAPI destinations have no timeout limits
BAPI destinations timeout after 5 seconds; use a DLQ for failed deliveries
CUse SNS HTTP subscription instead - no timeout
DIncrease the EventBridge timeout to 30 seconds
Q

A company wants to centralize events from production, staging, and development accounts into a single monitoring account. What is the recommended approach?

AUse SNS topics with cross-account subscriptions
BConfigure cross-account EventBridge with resource policies
CSet up Kinesis Data Streams for centralization
DUse CloudWatch Logs subscription filters

Further Reading

Related services

EventBridgeLambdaStep Functions