Build a Serverless API with Lambda, API Gateway, and DynamoDB
Answer
Scenario
An internal serverless API is needed for order management. Orders must be stored in a DynamoDB table with all access routed through a Lambda function — never direct database access. The Lambda execution role should follow least-privilege principles, limiting permissions to only what's necessary.
Task
- Create a DynamoDB table named
orderswithorderIdas the partition key - Create an IAM role called
lambda-orders-rolethat assumes Lambda permissions - Create a
orders-handlerLambda function using Python 3.12 with environment variableTABLE_NAME=orders(code provided at/tmp/handler.py) - Create a REST API named
orders-apiwith an/ordersendpoint supporting GET and POST methods - Deploy to a
devstage for public access