Skip to main content

Building Event-Driven Systems with EventBridge

Build event-driven systems with EventBridge: buses, schedule and pattern rules, Schema Registry, and Pipes to connect AWS services without glue code.

Overview and What You Will Learn

Amazon EventBridge is a serverless event bus: services publish events, rules match them against patterns, and matching events are delivered to targets such as Lambda, SQS, SNS or Step Functions. The publisher never knows who is listening, so adding a new consumer never means changing the publisher.

In this lab, you will:

  • Create an SNS topic and allow EventBridge to publish to it
  • Test an event pattern offline before deploying it
  • Create a custom event bus with a rule and publish a real event
  • Add a schedule rule and an event archive
  • Clean everything up in dependency order

Why This Matters in Production

Picture a trading platform like Zerodha. When a trade executes, a dozen downstream systems need to know: the ledger, tax records, notifications, risk checks and the audit log. If the trade service calls each one directly, any slow or failing call slows or fails the trade confirmation. With EventBridge the trade service publishes one event and every system subscribes independently. The same pattern powers security automation, such as alerting the security team when the root user signs in.

Core Principles

How Events Flow Through EventBridge

A producer puts an event on a bus, each rule on that bus evaluates it against its pattern, and every matching rule sends it to its targets. One rule can have up to 5 targets.

flowchart LR P([Producer]) -->|Publishes| B[Event bus] B --> R1{Rule 1
pattern} B --> R2{Rule 2
pattern} R1 -->|Match| T1[Lambda] R2 -->|Match| T2[SQS queue] R2 -->|Match| T3[SNS topic] classDef start fill:#475569,color:#FFFFFF classDef bus fill:#F97316,color:#FFFFFF classDef rule fill:#F59E0B,color:#111827 classDef target fill:#326CE5,color:#FFFFFF class P start class B bus class R1,R2 rule class T1,T2,T3 target

Which Event Bus Should You Use

EventBridge has three kinds of bus, and keeping each kind of event on the right one keeps rules simple.

Bus Receives
Default AWS service events, such as EC2 state changes and CloudTrail API calls
Partner Events from SaaS providers such as GitHub, Stripe and Datadog
Custom Events your own applications publish
Common Mistake

Putting your application events on the Default bus. It exists for AWS service events, and mixing the two makes filtering harder and adds noise. Create a Custom bus for your own events.

Schedule Rules and Event Pattern Rules

A schedule rule runs a target on a timer, like a managed cron job, using rate(5 minutes) or cron(0 2 * * ? *). An event pattern rule reacts when something happens. For new schedules, EventBridge Scheduler is the more capable service, with time zones, one-time schedules and higher scale, while rules with schedule expressions still work.

How to Write an Event Pattern

An event pattern is a JSON filter, and an event matches only if every field you list matches. Match EC2 terminations:

JSON
{
"source": ["aws.ec2"],
"detail-type": ["EC2 Instance State-change Notification"],
"detail": {
"state": ["terminated"]
}
}

Match root user console sign-ins, the classic security alert:

JSON
{
"source": ["aws.signin"],
"detail-type": ["AWS Console Sign In via CloudTrail"],
"detail": {
"userIdentity": {
"type": ["Root"]
}
}
}

Match S3 uploads under a prefix. The bucket must have EventBridge notifications turned on:

JSON
{
"source": ["aws.s3"],
"detail-type": ["Object Created"],
"detail": {
"bucket": { "name": ["devops-uploads-prod"] },
"object": { "key": [{ "prefix": "invoices/" }] }
}
}

Patterns also support suffix, anything-but, numeric ranges and exists checks.

Remember

Console sign-in events for the root user are often delivered in us-east-1, so create a root login rule in that Region and confirm where your sign-in events appear.

Schema Registry, Pipes, and Archives

Schema Registry discovers the structure of events on a bus and generates typed code bindings for Python, Java, TypeScript and Go, so your consumer already knows detail.orderId is a string. EventBridge Pipes connect a source (SQS, Kinesis, DynamoDB Streams, Kafka) to a target with optional filtering and enrichment, replacing a Lambda that only moves data. An archive stores events from a bus so you can replay them later.

flowchart LR S[(DynamoDB Stream)] --> F[Filter] F --> E[Enrich
optional Lambda] E --> T[SQS queue] classDef src fill:#475569,color:#FFFFFF classDef step fill:#F97316,color:#FFFFFF classDef tgt fill:#326CE5,color:#FFFFFF class S src class F,E step class T tgt
Tip

Turn on archiving from day one. You can only replay events that were archived, and replay is the fastest way to test a new rule against real traffic or recover after a consumer outage.

Cross-Account and Cross-Region Routing

A rule can target another bus in a different account or Region. Security teams use this to collect events from every account on one central bus, and DR designs use it to copy events to a standby Region.

Detailed Step-by-Step Practical Lab

Replace the email address with your own. The lab uses the AWS CLI, creates no always-on compute, and costs almost nothing.

  1. Create an SNS topic and subscribe your email. Confirm the subscription from your inbox before continuing:
Bash
export AWS_REGION=ap-south-1
export TOPIC_ARN=$(aws sns create-topic --name devops-event-alerts \
--query TopicArn --output text --region $AWS_REGION)
aws sns subscribe --topic-arn $TOPIC_ARN \
--protocol email --notification-endpoint rahul@devops.in --region $AWS_REGION
  1. Allow EventBridge to publish to the topic. Without this policy, rules created from the CLI deliver nothing:
Bash
cat > sns-policy.json << EOF
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": { "Service": "events.amazonaws.com" },
"Action": "sns:Publish",
"Resource": "$TOPIC_ARN"
}]
}
EOF
aws sns set-topic-attributes --topic-arn $TOPIC_ARN \
--attribute-name Policy --attribute-value file://sns-policy.json --region $AWS_REGION
  1. Test the pattern offline. test-event-pattern returns true when an event matches, so you catch mistakes before deploying:
Bash
cat > order-pattern.json << 'EOF'
{
"source": ["devops.orders"],
"detail-type": ["OrderPlaced"]
}
EOF
cat > sample-event.json << 'EOF'
{
"id": "11111111-2222-3333-4444-555555555555",
"version": "0",
"account": "123456789012",
"time": "2026-10-14T09:00:00Z",
"region": "ap-south-1",
"resources": [],
"source": "devops.orders",
"detail-type": "OrderPlaced",
"detail": { "orderId": "ORD-001", "city": "Mumbai", "amount": 450 }
}
EOF
aws events test-event-pattern \
--event-pattern file://order-pattern.json \
--event file://sample-event.json --region $AWS_REGION
  1. Create a custom bus, then a rule and a target on it:
Bash
aws events create-event-bus --name mumbai-orders-bus --region $AWS_REGION
aws events put-rule --name new-order-processor \
--event-bus-name mumbai-orders-bus \
--event-pattern file://order-pattern.json --region $AWS_REGION
aws events put-targets --rule new-order-processor \
--event-bus-name mumbai-orders-bus \
--targets "Id"="notify-team","Arn"="$TOPIC_ARN" --region $AWS_REGION
  1. Publish a custom event. The output should show FailedEntryCount: 0, and an email arrives within a minute:
Bash
aws events put-events --region $AWS_REGION --entries '[{
"EventBusName": "mumbai-orders-bus",
"Source": "devops.orders",
"DetailType": "OrderPlaced",
"Detail": "{\"orderId\": \"ORD-002\", \"city\": \"Mumbai\", \"amount\": 450}"
}]'
  1. Add a schedule rule on the default bus that fires every 5 minutes, then check it:
Bash
aws events put-rule --name devops-health-check \
--schedule-expression "rate(5 minutes)" --region $AWS_REGION
aws events put-targets --rule devops-health-check \
--targets "Id"="ping-team","Arn"="$TOPIC_ARN" --region $AWS_REGION
aws events describe-rule --name devops-health-check --region $AWS_REGION
  1. Archive the custom bus so its events can be replayed later:
Bash
export BUS_ARN=$(aws events describe-event-bus --name mumbai-orders-bus \
--query Arn --output text --region $AWS_REGION)
aws events create-archive --archive-name mumbai-orders-archive \
--event-source-arn $BUS_ARN --retention-days 7 --region $AWS_REGION
  1. Clean up. Remove targets before deleting rules, and rules before deleting the bus:
Bash
aws events remove-targets --rule devops-health-check --ids ping-team --region $AWS_REGION
aws events delete-rule --name devops-health-check --region $AWS_REGION
aws events remove-targets --rule new-order-processor \
--event-bus-name mumbai-orders-bus --ids notify-team --region $AWS_REGION
aws events delete-rule --name new-order-processor \
--event-bus-name mumbai-orders-bus --region $AWS_REGION
aws events delete-archive --archive-name mumbai-orders-archive --region $AWS_REGION
aws events delete-event-bus --name mumbai-orders-bus --region $AWS_REGION
aws sns delete-topic --topic-arn $TOPIC_ARN --region $AWS_REGION

Production Best Practices & Common Pitfalls

Common Mistake

Treating a schedule as a guarantee that earlier work succeeded. A schedule fires whether or not the last run failed, and delivery is at least once. Build idempotent targets that can safely run twice.

Security

Scope every target permission tightly. Grant EventBridge only the sns:Publish or lambda:InvokeFunction it needs on the exact resource, and restrict who can call PutEvents on shared buses.

  • Give failing targets a dead-letter queue. Attach an SQS queue to each target so events that cannot be delivered are kept instead of lost.
  • Test patterns before deploying. Run test-event-pattern with a realistic event, because a pattern with one wrong field silently matches nothing.
  • Keep one bus per domain. A Custom bus for orders and another for payments keeps rules readable and permissions narrow.
  • Use Pipes for plain routing. If a Lambda only reads a stream, filters and forwards, a Pipe does the same with configuration instead of code to maintain.
  • Design events as contracts. Include stable fields such as orderId and a version, and treat changes like API changes, since many consumers depend on them.

Quick Reference & Troubleshooting Commands

Command Description
aws events put-rule Create or update a rule
aws events put-targets Attach targets to a rule
aws events put-events Publish custom events
aws events test-event-pattern Check whether an event matches a pattern
aws events list-rules --event-bus-name NAME List rules on a bus
aws events create-archive Archive a bus for replay
aws events describe-rule --name NAME Inspect a rule's state and pattern
Problem Likely cause Fix
Rule never fires Pattern mismatch or wrong bus Run test-event-pattern and confirm the bus
Target gets nothing Missing permission on the target Add a resource policy for events.amazonaws.com
put-events shows failures Malformed Detail or missing bus name Check FailedEntryCount and the error message
S3 events never arrive EventBridge notifications are off Turn on EventBridge notifications for the bucket
Cannot replay events No archive existed at the time Create the archive before you need it

Resources

AWS Direct Connect vs VPN: Run Both as Failover

AWS Direct Connect vs VPN: Run Both as Failover

Run AWS Direct Connect as primary and Site-to-Site VPN as BGP failover. Size the backup, set route preference and test it before an outage does.

10 min read•Aug 2026
Lambda vs Fargate vs EC2 Spot: The Cost Crossover

Lambda vs Fargate vs EC2 Spot: The Cost Crossover

Lambda vs Fargate vs EC2 Spot, at the crossover where Lambda stops being cheaper — 2026 pricing, invocation thresholds, and interruption math.

5 min read•Aug 2026
Secrets Manager vs Parameter Store vs Vault

Secrets Manager vs Parameter Store vs Vault

Secrets Manager vs Parameter Store vs Vault: cost math, rotation, dynamic secrets and a decision flow, plus the Vault, IBM and OpenBao licensing context.

10 min read•Aug 2026
AWS VPC Security: Hardening Every Layer

AWS VPC Security: Hardening Every Layer

Harden your AWS VPC in layers: subnets, Security Groups, NACLs, Flow Logs, endpoints, and IAM conditions, with CLI examples for production.

10 min read•Jul 2026
Event-Driven Architecture on AWS Explained

Event-Driven Architecture on AWS Explained

Build event-driven systems on AWS with SQS, SNS, EventBridge and Kinesis: fan-out, DLQs, idempotent consumers and queue-based scaling.

11 min read•Jul 2026
S3 vs RDS vs DynamoDB: Choosing AWS Storage

S3 vs RDS vs DynamoDB: Choosing AWS Storage

Choosing S3, RDS, or DynamoDB wrong costs you in performance, cost, and scalability. Here is a practical decision guide based on your actual access patterns.

5 min read•Jul 2026
AWS Cost Optimisation: 8 Actions That Cut Bills

AWS Cost Optimisation: 8 Actions That Cut Bills

Cut your AWS bill without re-architecting: eight ordered steps from anomaly alerts and tagging to rightsizing, VPC endpoints, Savings Plans and Spot.

11 min read•Jul 2026
EC2 vs Lambda vs Fargate: Choosing AWS Compute

EC2 vs Lambda vs Fargate: Choosing AWS Compute

Choose between EC2, Lambda and Fargate using traffic shape, state and runtime limits, with worked cost break-evens instead of rules of thumb.

11 min read•Jul 2026

Explore More in AWS DevOps, Cost, and Machine Learning

All 6 Topics

Frequently Asked Questions

Is Building Event-Driven Systems with EventBridge free to learn on DevOps Network?

Yes - this topic, like everything on DevOps Network, is 100% free with no paywall or sign-up gate.

What does the Building Event-Driven Systems with EventBridge topic cover?

Build event-driven systems with EventBridge: buses, schedule and pattern rules, Schema Registry, and Pipes to connect AWS services without glue code.

Found a mistake, an outdated step or a broken link?