Amazon Cognito to AWS Lambda to Amazon DynamoDB

Amazon Cognito → AWS Lambda → Amazon DynamoDB

Create a user in Amazon Cognito, handle a Post Confirmation trigger with AWS Lambda, and store user details in Amazon DynamoDB.

This sample project demonstrates how to create a user in an Amazon Cognito User Pool, then automatically insert that user's details into a DynamoDB table once the user confirms their email. The Post Confirmation Lambda trigger handles the event from Cognito and uses the AWS SDK for JavaScript (v3) to write user data to the DynamoDB table.
Key attributes such as the user's unique ID (sub), email, and optional custom attributes are passed to Lambda, which then processes and persists this data. The table is configured in on-demand capacity mode (Pay Per Request) for cost efficiency and minimal management overhead.
This pattern deploys a Cognito User Pool, a User Pool Client, a DynamoDB table, and a Node.js AWS Lambda function as the trigger.

< 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/cognito-lambda-dynamodb

Deploy

cdk synthcdk deploy


Testing

See the GitHub repo for end-to-end tests using Jest and manual sign-up steps.

Cleanup

Delete the stack: cdk destroy.

Created by:

Vidit Shah

Vidit Shah

Software Engineer working @ServerlessCreed,making Serverless Courses and workshops

Follow on LinkedIn