Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions eventbridge-pipes-sqs-to-dynamodb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Amazon SQS to Amazon DynamoDB using Amazon EventBridge Pipes with Amazon API Gateway and CDK/Python

This pattern will send messages from an SQS queue to a DynamoDB table via API Gateway using EventBridge Pipes.

![Architecture](./architecture.png)

Learn more about this pattern at Serverless Land Patterns: [https://serverlessland.com/patterns/eventbridge-pipes-sqs-to-dynamodb](https://serverlessland.com/patterns/eventbridge-pipes-sqs-to-dynamodb)

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

## Requirements

- [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
- [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
- [AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/cli.html) installed and configured

## Deployment Instructions

1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository:
```bash
git clone https://github.com/aws-samples/serverless-patterns
```
2. Change directory to the pattern directory:
```bash
cd serverless-patterns/eventbridge-pipes-sqs-to-dynamodb
```
3. To manually create a virtualenv on MacOS and Linux:
```bash
$ python3 -m venv .venv
```
4. After the init process completes and the virtualenv is created, you can use the following
step to activate your virtualenv.
```bash
$ source .venv/bin/activate
```
5. If you are a Windows platform, you would activate the virtualenv like this:
```bash
% .venv\Scripts\activate.bat
```
6. Once the virtualenv is activated, you can install the required dependencies.
```bash
$ pip install -r requirements.txt
```
7. To deploy the application:
```bash
$ cdk deploy
```

## How it works

This template will create an SQS queue, EventBridge Pipe, API Gateway and a DynamoDB table.

Messages sent to the SQS queue are polled by EventBridge Pipe. EventBridge Pipe processes the messages and sends them to API Gateway endpoint. API Gateway transforms the message and writes the data to DynamoDB table using direct integration.

## Testing

Once this stack is deployed in your AWS account, copy the SQS queue name value from the output.

Alternatively, retrieve the queue URL using AWS CLI:
```sh
aws sqs list-queues --query 'QueueUrls[?contains(@, `EntryPointToEventbridgePipe`)]'
```

Then, send a message to the SQS queue as follows:
```sh
aws sqs send-message \
--queue-url "<REPLACE_WITH_OUTPUT_FROM_PREVIOUS_COMMAND>" \
--message-body '{"Message": "{\"content\":\"Test message\",\"params\":{\"name\":\"Mario\",\"surname\":\"Rossi\"}}"}'
```

Navigate to [AWS Console DynamoDB Tables](https://console.aws.amazon.com/dynamodbv2/home#tables) and check for a table with name `Audit-Table`.
When you check the DynamoDB table, you can see the entry with all the attributes parsed by API Gateway.

Alternatively, you can scan the table using AWS CLI:
```sh
aws dynamodb scan --table-name Audit-Table
```

## Cleanup

1. Delete the stack

```bash
cdk destroy
```

---

Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0
9 changes: 9 additions & 0 deletions eventbridge-pipes-sqs-to-dynamodb/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env python3
import os
import aws_cdk as cdk
from eventbridge_pipes_sqs_to_dynamodb.eventbridge_pipes_sqs_to_dynamodb import EventbridgePipesSqsToDynamodb

app = cdk.App()
stack = EventbridgePipesSqsToDynamodb(app, "EventbridgePipesSqsToDynamodb")

app.synth()
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions eventbridge-pipes-sqs-to-dynamodb/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "python3 app.py"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
{
"title": "Amazon SQS to Amazon DynamoDB via Amazon EventBridge Pipes using CDK/Python",
"description": "Send messages from an SQS queue to a DynamoDB table via API Gateway using EventBridge Pipes. Implemented with CDK/Python.",
"language": "Python",
"level": "300",
"framework": "AWS CDK",
"introBox": {
"headline": "How it works",
"text": [
"Messages sent to the Amazon SQS queue are polled by Amazon EventBridge Pipe.",
"Amazon EventBridge Pipe processes the messages and sends them to the Amazon API Gateway endpoint.",
"Amazon API Gateway transforms the message and writes the data to the Amazon DynamoDB table using direct integration."
]
},
"gitHub": {
"template": {
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/eventbridge-pipes-sqs-to-dynamodb",
"templateURL": "serverless-patterns/eventbridge-pipes-sqs-to-dynamodb",
"projectFolder": "eventbridge-pipes-sqs-to-dynamodb",
"templateFile": "eventbridge_pipes_sqs_to_dynamodb/eventbridge_pipes_sqs_to_dynamodb.py"
}
},
"services": {
"from": {
"serviceName": "Amazon SQS",
"serviceURL": "/sqs/"
},
"to": {
"serviceName": "Amazon DynamoDB",
"serviceURL": "/dynamodb/"
}
},
"patternArch": {
"icon1": {
"x": 10,
"y": 50,
"service": "sqs",
"label": "Amazon SQS"
},
"icon2": {
"x": 37,
"y": 50,
"service": "eventbridge",
"label": "EventBridge Pipes"
},
"icon3": {
"x": 63,
"y": 50,
"service": "apigw",
"label": "API Gateway"
},
"icon4": {
"x": 90,
"y": 50,
"service": "dynamodb",
"label": "DynamoDB"
},
"line1": {
"from": "icon1",
"to": "icon2"
},
"line2": {
"from": "icon2",
"to": "icon3"
},
"line3": {
"from": "icon3",
"to": "icon4"
}
},
"resources": {
"bullets": [
{
"text": "Amazon SQS Developer Guide",
"link": "https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/welcome.html"
},
{
"text": "Amazon EventBridge Pipes Documentation",
"link": "https://docs.aws.amazon.com/eventbridge/latest/userguide/eb-pipes-event-source.html"
},
{
"text": "AWS CloudFormation API for Pipes",
"link": "https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-pipes-pipe.html"
},
{
"text": "Amazon EventBridge Pipes CDK v2 Python Reference",
"link": "https://docs.aws.amazon.com/cdk/api/v2/python/aws_cdk.aws_pipes/CfnPipe.html"
},
{
"text": "Amazon API Gateway DynamoDB Integration",
"link": "https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-overview-developer-experience.html"
}
]
},
"deploy": {
"text": ["cdk deploy"]
},
"testing": {
"text": ["See the README in the GitHub repo for detailed testing instructions."]
},
"cleanup": {
"text": ["Delete the stack: <code>cdk destroy</code>."]
},
"authors": [
{
"name": "Michele Scarimbolo",
"image": "https://avatars.githubusercontent.com/u/229997073",
"bio": "Technical Account Manager at AWS. Serverless specialist and enthusiast.",
"linkedin": "michele-scarimbolo",
"twitter": ""
}
],
"patternType": "Serverless"
}
Loading