Amazon API Gateway REST API to AWS Lambda to Amazon DynamoDB with X-Ray

API Gateway → AWS Lambda → Amazon DynamoDB → X-Ray

Create an API Gateway endpoint integrated with Lambda and DynamoDB with X-Ray enabled.

AWS X-Ray records and visualizes requests made by applications, making it a great tool to analyze and debug applications built using a microservices and serverless architecture.
This CDK application demonstrates how to integrate X-Ray SDK in Lambda functions to observe into downstream API calls. This example creates an Amazon API Gateway REST API that uses a Lambda function as the backend to scan a DynamoDB table. The REST API and Lambda function both have X-Ray tracing enabled. X-Ray SDK is also integrated in the Lambda function to observe into the API call to the downstream DynamoDB table.

< 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 apigw-lambda-dynamodb-xray/cdk/lib/

Deploy

cdk deploy


Testing

See the GitHub repo for detailed testing instructions.

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:

Guyu Ye

Guyu Ye

Guyu is a Sustainability App Architect at AWS Professional Services.