Home β€Ί AWS Resources β€Ί Amazon EventBridge

Amazon EventBridge

Event-driven architecture on AWS with EventBridge: routing rules, schema discovery, and CDK setup.

What Is EventBridge?

EventBridge is AWS's serverless event bus. You publish events (structured JSON) to a bus, define rules that match event patterns, and route matching events to targets. Lambda, SQS, Step Functions, other AWS accounts, or even third-party SaaS APIs.

It's the backbone of event-driven architectures on AWS. Unlike SNS (which is pub/sub with topic-based fan-out), EventBridge gives you content-based routing: you can match on any field in the event payload and route to different targets based on the content.

When to Use It

Good fit:

  • Decoupling microservices (producers don't need to know about consumers)
  • Cross-account event routing
  • Reacting to AWS service events (EC2 state changes, S3 uploads, CodePipeline status)
  • Scheduled tasks (cron-like scheduling built in)
  • Audit trails and compliance workflows

Use SNS instead when:

  • You need raw pub/sub fan-out to many subscribers
  • Message ordering matters (use SQS FIFO with SNS)
  • You need message filtering on attributes rather than content

Use SQS instead when:

  • You need guaranteed delivery with retry/dead-letter queues
  • Consumers process at their own pace (backpressure)
  • Exactly-once processing matters

Key Concepts

Event Bus

A logical channel for events. AWS provides a default bus that receives all AWS service events. Create custom buses for your application events to keep them separate.

Rules and Patterns

Rules match events using patterns. Patterns can match on:

  • Event source and detail-type (the "envelope")
  • Any field in the event body (nested JSON matching)
  • Prefix, suffix, numeric range, exists/not-exists
{
  "source": ["com.myapp.orders"],
  "detail-type": ["OrderPlaced"],
  "detail": {
    "amount": [{ "numeric": [">", 1000] }],
    "region": ["us-east-1", "us-west-2"]
  }
}

Targets

Each rule can have up to 5 targets. Targets include Lambda, SQS, SNS, Step Functions, Kinesis, API Gateway, CloudWatch Logs, and cross-account event buses.

Schema Registry

EventBridge can discover and store schemas from events flowing through your bus. Useful for documentation and code generation, though in practice most teams define schemas upfront.

CDK Example

import { EventBus, Rule } from 'aws-cdk-lib/aws-events';
import { LambdaFunction, SqsQueue } from 'aws-cdk-lib/aws-events-targets';

// Custom event bus
const bus = new EventBus(this, 'AppEventBus', {
  eventBusName: 'my-app-events',
});

// Rule: route high-value orders to processing Lambda
new Rule(this, 'HighValueOrderRule', {
  eventBus: bus,
  eventPattern: {
    source: ['com.myapp.orders'],
    detailType: ['OrderPlaced'],
    detail: {
      amount: [{ numeric: ['>', 1000] }],
    },
  },
  targets: [new LambdaFunction(highValueOrderHandler)],
});

// Rule: send all order events to audit queue
new Rule(this, 'OrderAuditRule', {
  eventBus: bus,
  eventPattern: {
    source: ['com.myapp.orders'],
  },
  targets: [new SqsQueue(auditQueue)],
});

Publishing Events

import { EventBridgeClient, PutEventsCommand } from '@aws-sdk/client-eventbridge';

const client = new EventBridgeClient({});

await client.send(new PutEventsCommand({
  Entries: [{
    EventBusName: 'my-app-events',
    Source: 'com.myapp.orders',
    DetailType: 'OrderPlaced',
    Detail: JSON.stringify({
      orderId: 'ORD-12345',
      customerId: 'CUST-789',
      amount: 1500,
      region: 'us-east-1',
    }),
  }],
}));

Architecture Patterns

Fan-out with filtering

One event, multiple consumers, each getting only what they care about. The order service publishes OrderPlaced. The billing service picks up orders over $1000, the notification service picks up all orders, the analytics service picks up everything.

Cross-account routing

Forward events from workload accounts to a central observability account. Each account publishes to its own bus, rules forward to a shared bus in the operations account.

Dead-letter queues

Attach an SQS DLQ to any rule target. If the target fails (Lambda error, SQS full), the event goes to the DLQ instead of being lost.

Cost Considerations

  • $1.00 per million events published (custom events)
  • AWS service events on the default bus are free
  • Schema registry discovery: $0.10 per million events ingested
  • No charge for rules. Only matched events that invoke targets

EventBridge is cheap at moderate scale. At very high volumes (millions of events/minute), the per-event cost adds up and you might want Kinesis instead for raw throughput.

Further Reading

Looking for hands-on help? View my AWS architecture services β†’

Building event-driven systems?

Drop me a message β€” I typically respond within one business day.