What you will learn
- What event-driven architecture is and why it decouples services better than direct calls
- EventBridge event buses — Default, Partner, and Custom
- Schedule rules — running tasks on a timer without managing cron servers
- Event pattern rules — reacting automatically when something happens in AWS
- How to write event pattern filters to match exactly what you need
- Schema Registry — auto-discovering event structure for type-safe code
- EventBridge Pipes — connecting sources to targets with filtering and transformation
- Cross-account and cross-region event routing
- Real production patterns — security alerting, deployment triggers, data pipelines
Why this matters
At Zerodha, when a trade is executed, twelve downstream systems need to know — ledger, tax records, SMS notification, email, portfolio analytics, risk management, audit log, and more. Calling each one directly from the trade service creates tight coupling. Any slow or failed downstream call slows or fails the trade confirmation. EventBridge lets the trade service publish one event. Every downstream system subscribes independently. The trade service does not know or care who is listening.
At Razorpay, when the root IAM user logs in at any time, the security team gets an immediate alert. When a production EC2 instance is terminated, an incident is auto-created. None of this requires custom polling or cron jobs. EventBridge watches AWS and reacts instantly.
What is Amazon EventBridge
EventBridge is a serverless event bus. Services publish events. Rules decide what to do with each event. Targets receive and act on them.
Something happens anywhere ↓Event published to EventBridge ↓Rules evaluated — does this event match any pattern? ↓Matching rules send the event to their targets ↓Targets act: Lambda runs, SQS receives message, Step Functions startsThe key insight: the publisher does not know who is listening. Adding a new consumer never requires changing the publisher. This is loose coupling.
Three Event Buses
Default Event Bus:
Receives all events from AWS services automatically. EC2 state changes, S3 uploads, CodeBuild results, CloudTrail API calls, RDS snapshots — all flow here with zero configuration.
EC2 instance stopped → event automatically on Default BusS3 object created → event automatically on Default BusIAM user created → event automatically on Default BusPartner Event Bus:
Third-party SaaS services send events directly into your AWS account. Datadog, GitHub, Stripe, Zendesk, PagerDuty — when something happens in their system, an event appears in your EventBridge.
GitHub pull request merged → GitHub sends event to your Partner BusStripe payment succeeded → Stripe sends event to your Partner BusCustom Event Bus:
Your own applications publish custom events here. One application publishes. Multiple applications subscribe. No direct calls between them.
Order Service publishes: { "source": "devops.orders", "detail-type": "OrderPlaced", ... }Fraud Service subscribes → gets the eventEmail Service subscribes → gets the eventAnalytics subscribes → gets the eventTwo Ways to Use EventBridge
Schedule Rules — run on a timer:
Like a managed cron job in the cloud. No server needed. Runs a Lambda, starts a Step Functions workflow, or sends a message to SQS on a schedule.
Every day at 2 AM → trigger Lambda → clean up old logsEvery 5 minutes → trigger Lambda → check health of external payment APIFirst day of month → start Step Functions → generate monthly invoicesEvery weekday 8:30 AM → send SQS message → scale up trading infrastructureTwo schedule formats:
Rate expression: rate(5 minutes) rate(1 hour) rate(7 days)Cron expression: cron(0 2 * * ? *) (2 AM UTC every day)Event Pattern Rules — react to something that happened:
Watch for specific events and trigger a response automatically.
Root user signs into AWS console ↓ EventBridge sees: source=aws.signin, userIdentity.type=Root ↓ Rule matches ↓ SNS sends email to security team immediately EC2 instance terminated ↓ EventBridge sees: source=aws.ec2, detail-type=EC2 Instance State-change, state=terminated ↓ Rule matches ↓ Lambda creates a PagerDuty incident CodeBuild build fails ↓ EventBridge sees: source=aws.codebuild, detail.build-status=FAILED ↓ Rule matches ↓ Slack notification sent via LambdaWriting Event Patterns
An event pattern is a JSON filter. An event matches if all specified fields match.
Match any EC2 state change:
{ "source": ["aws.ec2"], "detail-type": ["EC2 Instance State-change Notification"]}Match only EC2 terminations:
{ "source": ["aws.ec2"], "detail-type": ["EC2 Instance State-change Notification"], "detail": { "state": ["terminated"] }}Match root user login (security critical):
{ "source": ["aws.signin"], "detail-type": ["AWS Console Sign In via CloudTrail"], "detail": { "userIdentity": { "type": ["Root"] } }}Match S3 uploads to a specific prefix:
{ "source": ["aws.s3"], "detail-type": ["Object Created"], "detail": { "bucket": { "name": ["devops-uploads-prod"] }, "object": { "key": [{ "prefix": "invoices/" }] } }}Patterns support: exact match, prefix, suffix, anything-but, numeric ranges, and exists/not-exists checks.
EventBridge Targets — Where Events Go
| Target | What happens |
|---|---|
| Lambda function | Function invoked with event as input |
| SQS queue | Message added to queue |
| SNS topic | Notification published to all subscribers |
| Step Functions | Workflow execution started |
| ECS task | New container task launched |
| API Gateway | HTTP request made |
| Kinesis Data Streams | Record added to stream |
| Another EventBridge bus | Event forwarded (cross-account) |
| CodeBuild | Build triggered |
| CodePipeline | Pipeline execution started |
One rule can have up to 5 targets. The same event is delivered to all matching targets simultaneously.
Schema Registry — Know Your Event Structure
EventBridge can automatically discover the structure of every event flowing through your buses. The Schema Registry stores these structures and generates typed code in Python, Java, TypeScript, or Go.
Events flow through EventBridge ↓Schema Registry discovers their structure automatically ↓You download a generated code binding ↓Your Lambda already knows: event.detail.orderId is a string event.detail.amount is a numberNo manual JSON parsing. Type-safe code from the start.Finding schemas:
EventBridge → Schema Registry → Discovered schemasOr search the AWS schema registry: 100+ pre-built schemas for all AWS servicesEventBridge Pipes — Simple Point-to-Point Connections
Pipes connect a source directly to a target with optional filtering and transformation in between. No Lambda glue code needed for simple routing.
Source (SQS, Kinesis, DynamoDB Streams, Kafka) ↓Filter (optional — only pass matching events) ↓Enrichment (optional — Lambda adds data to the event) ↓Target (Lambda, Step Functions, SQS, HTTP endpoint)Example without Pipes:
DynamoDB Streams → Lambda (reads stream, filters, formats) → SQSYou write and maintain the Lambda glue codeSame flow with Pipes:
DynamoDB Streams → Pipe (filter + transform) → SQSNo Lambda. No code. Just configuration.Cross-Account and Cross-Region Events
EventBridge can route events between AWS accounts and regions.
Cross-account:
Account A (Production) → Custom Bus → EventBridge Rule ↓ Send to Account BAccount B (Security) → receives all production eventsSecurity team monitors all accounts from one central busUseful for: centralising security events, aggregating audit logs, sharing events between team accounts.
Cross-region:
ap-south-1 (primary) → event published ↓ rule forwards toap-southeast-1 (secondary) → local processingUseful for: DR architectures, replicating events to a standby region.
Real Production Patterns
Pattern 1 — Security alerting:
CloudTrail logs any API call → EventBridge Default BusRule: match any action by Root user OR any DeleteBucket callTarget: SNS → email to security teamResponse time: under 30 seconds from action to alertPattern 2 — Auto-tagging new resources:
EC2 instance launched without required tagsRule: match EC2 RunInstances without Department tagTarget: Lambda → adds default tags automaticallyNo manual compliance enforcement neededPattern 3 — Deployment pipeline trigger:
Developer merges PR to main branchGitHub (Partner Event Bus) sends PullRequestMerged eventRule matchesTarget: CodePipeline → deployment starts automaticallyPattern 4 — Scheduled data pipeline:
Every night at midnightEventBridge schedule firesTarget: Glue job → transforms yesterday's data from S3 to ParquetNo cron server. No EC2. Fully serverless.Hands-on Lab — Schedule Rule and Security Alert Rule
Step 1 — Create an SNS topic for alerts
SNS → Topics → Create topicType: Standard Name: devops-security-alertsCreate topic Subscribe your email:Subscriptions → Create subscription → Email → your email → CreateConfirm from inbox before continuing.Step 2 — Create a Schedule Rule (runs every 5 minutes)
EventBridge → Rules → Create ruleName: devops-health-checkRule type: ScheduleSchedule pattern: Rate → 5 minutesNext Target: SNS topic → devops-security-alertsMessage: Health check ping from EventBridgeCreate rule Within 5 minutes an email arrives. EventBridge is running your schedule.Step 3 — Create a Security Alert Rule (root login)
EventBridge → Rules → Create ruleName: root-login-alertRule type: Event patternEvent source: AWS events Event pattern — paste:{ "source": ["aws.signin"], "detail-type": ["AWS Console Sign In via CloudTrail"], "detail": { "userIdentity": { "type": ["Root"] } }}Next → Target: SNS topic → devops-security-alertsCreate rule Test it: log in as root user → within 60 seconds an email arrives.Step 4 — Create a Custom Event Bus
EventBridge → Event buses → Create event busName: devops-orders-busCreate event bus EventBridge → Rules → Create ruleEvent bus: devops-orders-bus (not the default)Name: new-order-processorEvent pattern:{ "source": ["devops.orders"], "detail-type": ["OrderPlaced"]}Target: SNS → devops-security-alerts (reusing for demo)Create ruleStep 5 — Publish a custom event and test
aws events put-events \ --entries '[{ "EventBusName": "devops-orders-bus", "Source": "devops.orders", "DetailType": "OrderPlaced", "Detail": "{\"orderId\": \"ORD-001\", \"city\": \"Mumbai\", \"amount\": 450}" }]' \ --region ap-south-1Check your email — the order event triggers the SNS notification.Your custom application event flowing through EventBridge to a target.Step 6 — Cleanup
EventBridge → Rules → delete devops-health-check and root-login-alertEventBridge → Event buses → delete devops-orders-busSNS → devops-security-alerts → Delete topicCommon Mistakes to Avoid
Common MistakePutting business logic rules in the wrong event bus. Custom application events belong on a Custom Event Bus — not the Default Bus. The Default Bus is for AWS service events. Mixing them makes filtering complex and creates unnecessary noise.
Common MistakeUsing EventBridge Schedules and forgetting they still run when your Lambda has errors. A schedule fires whether or not the previous execution succeeded. If your Lambda fails, the next schedule fires and tries again. Build idempotent targets that can safely run multiple times.
TipEventBridge archives let you replay past events. Enable archiving on your event bus and you can replay any event from the past — debugging a production issue, testing a new rule against real historical events, recovering from a consumer outage. Turn it on from day one — you cannot replay events that were not archived.