Integrate AWS Lambda SnapStart function with Amazon API Gateway

Amazon API Gateway REST API → AWS Lambda → Amazon DynamoDB

This pattern demonstrates how to create a REST API using Amazon API Gateway, AWS Lambda with SnapStart, and Amazon DynamoDB.

This pattern creates a REST API for managing car records using API Gateway and Lambda with SnapStart enabled.
The Lambda function is Python 3.12-based and includes a live alias that's integrated with API Gateway for seamless deployments.
Lambda SnapStart persists the initialized state of the Lambda runtime, significantly reducing cold start times for function initialization.
DynamoDB stores car records with a partition key of 'id', providing a scalable NoSQL database backend for the REST API.

< 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/apigw-python-cdk-lambda-snapstart

Deploy

python3 -m venv .venvsource .venv/bin/activatepip install -r requirements.txtcdk bootstrapcdk deploy


Testing

Get the CarEndpoint from stack outputs, then test the endpoint to create a new car record:
curl --location --request POST "$ENDPOINT/cars" --header 'Content-Type: application/json' --data-raw '{"make":"Porsche","model":"992","year":"2022","color":"White"}'
Change the endpoint and HTTP method to test other operations:
GET /cars/{carId} - Retrieve a car
PUT /cars/{carId} - Update a car
DELETE /cars/{carId} - Delete a car

Cleanup

Delete the stack: cdk destroy.

Created by:

Matia Rasetina

Matia Rasetina

Senior Software Engineer @ Elixirr Digital

Follow on LinkedIn