|
| 1 | +# Amazon SQS to Amazon DynamoDB using Amazon EventBridge Pipes with Amazon API Gateway and CDK/Python |
| 2 | + |
| 3 | +This pattern will send messages from an SQS queue to a DynamoDB table via API Gateway using EventBridge Pipes. |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | +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) |
| 8 | + |
| 9 | +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. |
| 10 | + |
| 11 | +## Requirements |
| 12 | + |
| 13 | +- [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. |
| 14 | +- [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured |
| 15 | +- [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git) |
| 16 | +- [AWS CDK](https://docs.aws.amazon.com/cdk/latest/guide/cli.html) installed and configured |
| 17 | + |
| 18 | +## Deployment Instructions |
| 19 | + |
| 20 | +1. Create a new directory, navigate to that directory in a terminal and clone the GitHub repository: |
| 21 | + ```bash |
| 22 | + git clone https://github.com/aws-samples/serverless-patterns |
| 23 | + ``` |
| 24 | +2. Change directory to the pattern directory: |
| 25 | + ```bash |
| 26 | + cd serverless-patterns/eventbridge-pipes-sqs-to-dynamodb |
| 27 | + ``` |
| 28 | +3. To manually create a virtualenv on MacOS and Linux: |
| 29 | + ```bash |
| 30 | + $ python3 -m venv .venv |
| 31 | + ``` |
| 32 | +4. After the init process completes and the virtualenv is created, you can use the following |
| 33 | +step to activate your virtualenv. |
| 34 | + ```bash |
| 35 | + $ source .venv/bin/activate |
| 36 | + ``` |
| 37 | +5. If you are a Windows platform, you would activate the virtualenv like this: |
| 38 | + ```bash |
| 39 | + % .venv\Scripts\activate.bat |
| 40 | + ``` |
| 41 | +6. Once the virtualenv is activated, you can install the required dependencies. |
| 42 | + ```bash |
| 43 | + $ pip install -r requirements.txt |
| 44 | + ``` |
| 45 | +7. To deploy the application: |
| 46 | + ```bash |
| 47 | + $ cdk deploy |
| 48 | + ``` |
| 49 | + |
| 50 | +## How it works |
| 51 | + |
| 52 | +This template will create an SQS queue, EventBridge Pipe, API Gateway and a DynamoDB table. |
| 53 | + |
| 54 | +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. |
| 55 | + |
| 56 | +## Testing |
| 57 | + |
| 58 | +Once this stack is deployed in your AWS account, copy the SQS queue name value from the output. |
| 59 | + |
| 60 | +Alternatively, retrieve the queue URL using AWS CLI: |
| 61 | +```sh |
| 62 | +aws sqs list-queues --query 'QueueUrls[?contains(@, `EntryPointToEventbridgePipe`)]' |
| 63 | +``` |
| 64 | + |
| 65 | +Then, send a message to the SQS queue as follows: |
| 66 | +```sh |
| 67 | +aws sqs send-message \ |
| 68 | + --queue-url "<REPLACE_WITH_OUTPUT_FROM_PREVIOUS_COMMAND>" \ |
| 69 | + --message-body '{"Message": "{\"content\":\"Test message\",\"params\":{\"name\":\"Mario\",\"surname\":\"Rossi\"}}"}' |
| 70 | +``` |
| 71 | + |
| 72 | +Navigate to [AWS Console DynamoDB Tables](https://console.aws.amazon.com/dynamodbv2/home#tables) and check for a table with name `Audit-Table`. |
| 73 | +When you check the DynamoDB table, you can see the entry with all the attributes parsed by API Gateway. |
| 74 | + |
| 75 | +Alternatively, you can scan the table using AWS CLI: |
| 76 | +```sh |
| 77 | +aws dynamodb scan --table-name Audit-Table |
| 78 | +``` |
| 79 | + |
| 80 | +## Cleanup |
| 81 | + |
| 82 | +1. Delete the stack |
| 83 | + |
| 84 | +```bash |
| 85 | +cdk destroy |
| 86 | +``` |
| 87 | + |
| 88 | +--- |
| 89 | + |
| 90 | +Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 91 | + |
| 92 | +SPDX-License-Identifier: MIT-0 |
0 commit comments