Amazon DynamoDB to AWS Lambda

Amazon DynamoDB → AWS Lambda

Invoke a Lambda function from changes to a DynamoDB table

The CDK stack deploys a Lambda function, a DynamoDB table, and the minimum IAM resources required to run the application.
When items are written or updated in the DynamoDB table, the changes are sent to a stream. This pattern configures a Lambda function to poll this stream. The function is invoked with a payload containing the contents of the table item that changed.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/dynamodb-lambda-cdk

Deploy

cdk deploy


Testing

After deployment, add an item to the DynamoDB table. Go to the CloudWatch Logs for the deployed Lambda function. You will see the event is logged out containing the item data.

Cleanup

1. Delete the stack: npx cdk destroy.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus".
3. You see a message confirming DELETE_COMPLETE.

Created by:

Rohan Mehta

Rohan Mehta

Associate Cloud Application Architect at AWS.