AWS Builder Center
Building Event-Driven Microservices with AWS EventBridge, Lambda, and DynamoDB

Building Event-Driven Microservices with AWS EventBridge, Lambda, and DynamoDB

Learn how to decouple modern microservices and build resilient, scalable event-driven architectures on AWS using Amazon EventBridge, AWS Lambda, and Amazon DynamoDB.

Event-driven architecture (EDA) has become the gold standard for building modern, highly scalable applications in the cloud. By decoupling components and communicating via asynchronous events, teams can build systems that are flexible, fault-tolerant, and easy to maintain.
In this guide, we will explore how to set up an event-driven microservice pattern using Amazon EventBridge, AWS Lambda, and Amazon DynamoDB.
  1. Architecture Overview
    In a typical event-driven setup:
Event Producers: Microservices publish events when state changes occur (e.g., an OrderPlaced event).
Event Router (Amazon EventBridge): Receives events, evaluates routing rules, and delivers events to target destinations.
Event Consumers (AWS Lambda): Process event payloads asynchronously and update persistent storage (Amazon DynamoDB).
  1. Defining the Event Payload
    Standardizing your event structure makes routing and integration easier across teams. Here is an example schema for an OrderPlaced event published to an EventBridge custom event bus:
JSON:
{
"Source": "com.myapp.orders",
"DetailType": "OrderPlaced",
"Detail": JSON.stringify({
"orderId": "ord-987654",
"customerId": "usr-12345",
"totalAmount": 149.99,
"timestamp": "2026-10-12T10:00:00Z"
}),
"EventBusName": "OrdersBus"
}
3. Configuring EventBridge Rules
EventBridge rules allow you to pattern-match incoming events and target specific consumers without tightly coupling services.
To capture only OrderPlaced events from the com.myapp.orders service, define an event pattern like this:
JSON
{
"source": ["com.myapp.orders"],
"detail-type": ["OrderPlaced"]
}
When an event matches this pattern, EventBridge invokes your consumer Lambda function automatically.
  1. Processing Events in AWS Lambda
    Here is a Node.js AWS SDK v3 example of a consumer Lambda function that receives the event and persists it directly to DynamoDB:
JavaScript:
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
import { DynamoDBDocumentClient, PutCommand } from "@aws-sdk/lib-dynamodb";
const client = new DynamoDBClient({});
const docClient = DynamoDBDocumentClient.from(client);
export const handler = async (event) => {
console.log("Received Event:", JSON.stringify(event, null, 2));
const order = event.detail;
const params = {
TableName: process.env.ORDERS_TABLE,
Item: {
orderId: order.orderId,
customerId: order.customerId,
amount: order.totalAmount,
status: "PROCESSING",
createdAt: order.timestamp,
},
};
try {
await docClient.send(new PutCommand(params));
return { statusCode: 200, body: "Order successfully saved to DynamoDB" };
} catch (error) {
console.error("Error writing to DynamoDB:", error);
throw error;
}
};
5. Best Practices for Event-Driven Systems
Idempotency: Always ensure consumers can safely process the same event multiple times without unintended side effects.
Dead-Letter Queues (DLQ): Attach an Amazon SQS DLQ to your EventBridge target to capture failed invocations and prevent lost events.
Schema Registry: Use the EventBridge Schema Registry to discover and enforce event formats across development 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