AWS Builder Center
Building Event-Driven Architectures with AWS Lambda and Amazon EventBridge

Building Event-Driven Architectures with AWS Lambda and Amazon EventBridge

A modern tech illustration shows a serverless data pipeline on AWS. Data flows from ingestion sources (IoT, APIs) into Amazon EventBridge, which routes it. Parallel paths show AWS Lambda functions processing and enriching data before storing it in Amazon DynamoDB (NoSQL) or archiving it to Amazon S3 (Data Lake). A comprehensive monitoring section using Amazon CloudWatch tracks logs alarms, and dashboards, visualized by an operator. Entire flow is connected by arrows within a clean, vibrant vector layout.

Building resilient cloud architectures, SOC threat detection workflows, & secure networks.
Event-driven architecture (EDA) has become the gold standard for constructing scalable, decoupled, and highly resilient cloud applications. In traditional monolithic architectures, services communicate directly via synchronous request-response loops. While simple initially, this tight coupling makes scaling, isolating failures, and expanding system capabilities increasingly complex over time.
By adopting an event-driven design pattern on AWS, microservices communicate asynchronously via events. This guide explores how to build a production-grade event pipeline using Amazon EventBridge, AWS Lambda, and Amazon DynamoDB. Architectural Overview
In this pattern, applications publish state changes (events) to an event bus. Amazon EventBridge acts as the central router, inspecting incoming events and matching them against custom rules to trigger down-stream handlers such as AWS Lambda.

Core Components

  • Event Producer: An application, API Gateway, or third-party SaaS service emitting structured JSON events.
  • Amazon EventBridge: The central event bus evaluating filtering rules and routing payloads asynchronously.
  • AWS Lambda: Ephemeral compute functions executing domain logic (e.g., processing orders, sending notifications).
  • Amazon DynamoDB: A high-throughput, low-latency NoSQL database for persistence.
  • Amazon CloudWatch: Centralized logs and metrics provider monitoring execution and latency.

Key Benefits of Event-Driven Systems

  1. Loose Coupling: Producers have zero awareness of consumers. New features or services can subscribe to existing event buses without modifying producer code.
  1. Resilience & Fault Isolation: If a downstream consumer service encounters an outage or exception, incoming events are safely buffered using Dead-Letter Queues (DLQs) without impacting the upstream producer.
  1. Independent Scalability: AWS Lambda automatically scales execution instances in response to incoming event volumes.

Step-by-Step Implementation

Step 1: Define the Schema

A standardized JSON event structure ensures consistency across microservices:
JSON
{
"version": "0",
"id": "c2b3e456-7890-abcd-ef12-34567890abcd",
"detail-type": "OrderCreated",
"source": "com.mycompany.orders",
"account": "123456789012",
"time": "2026-11-06T10:30:00Z",
"region": "us-east-1",
"detail": {
"orderId": "ORD-99214",
"customerId": "CUST-402",
"amount": 149.99,
"status": "PENDING"
}
}

Step 2: Implement the Lambda Handler

Below is a Python-based AWS Lambda function that handles  OrderCreated  events and records them in DynamoDB:
Python
import json
import os
import boto3
from botocore.exceptions import ClientError

dynamodb = boto3.resource('dynamodb')
TABLE_NAME = os.environ.get('TABLE_NAME', 'OrdersTable')
table = dynamodb.Table(TABLE_NAME)

def lambda_handler(event, context):
print(f"Received event: {json.dumps(event)}")
try:
detail = event.get('detail', {})
order_id = detail.get('orderId')
customer_id = detail.get('customerId')
amount = detail.get('amount')
# Persist event data to DynamoDB
response = table.put_item(
Item={
'OrderId': order_id,
'CustomerId': customer_id,
'Amount': str(amount),
'Status': 'PROCESSED',
'ProcessedAt': event.get('time')
}
)
return {
'statusCode': 200,
'body': json.dumps({'message': f'Order {order_id} successfully processed.'})
}
except ClientError as e:
print(f"DynamoDB ClientError: {e.response['Error']['Message']}")
raise e

Step 3: Infrastructure as Code (AWS SAM)

Define your resources declaratively using the AWS Serverless Application Model (SAM):
YAML
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: EventBridge to Lambda to DynamoDB Serverless Pipeline

Resources:
OrdersTable:
Type: AWS::Serverless::SimpleTable
Properties:
PrimaryKey:
Name: OrderId
Type: String

ProcessOrderFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: src/
Handler: app.lambda_handler
Runtime: python3.11
Environment:
Variables:
TABLE_NAME: !Ref OrdersTable
Policies:
- DynamoDBCrudPolicy:
TableName: !Ref OrdersTable
Events:
OrderCreatedEvent:
Type: EventBridgeRule
Properties:
Pattern:
source:
- com.mycompany.orders
detail-type:
- OrderCreated

Best Practices for Production Workflows

  • Idempotency: Ensure consumer Lambda functions can process duplicate event deliveries gracefully using unique event identifiers ( detail.orderId ).
  • Dead-Letter Queues (DLQ): Configure Amazon SQS DLQs on EventBridge targets and Lambda async invocations to capture failed events for retry.
  • Structured Logging: Enable JSON-formatted logging in Lambda to simplify observability and debugging with Amazon CloudWatch Insights.

Conclusion

By leveraging EventBridge and Lambda, developers can build scalable, fault-tolerant applications without managing dedicated broker instances. This pattern reduces architectural overhead, optimizes compute costs, and enables rapid development across decoupled teams.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article