A lightweight, serverless Order Management API built using:
- ✅ AWS Lambda + API Gateway (REST)
- 🧰 AWS Lambda Powertools for Python (logging, tracing, metrics, idempotency, feature flags)
- 📦 DynamoDB as the order database
- 🛠️ Pydantic for request validation
- 🚀 LocalStack for local AWS emulation and testing
- Create and fetch orders
- Type-safe payloads with validation using Pydantic
- Idempotent
POST /order
endpoint (prevents double orders) - Feature flags controlled via AWS AppConfig
- Metrics, logs, and tracing via Powertools
- Fully local development possible with LocalStack
Client → API Gateway → Lambda (APIGatewayRestResolver + Pydantic)
├── DynamoDB (Orders table)
├── AWS AppConfig (feature flags)
├── AWS CloudWatch (metrics/logs)
└── AWS X-Ray (tracing)
Layer | Tool / Library |
---|---|
API | AWS API Gateway (REST) |
Function | AWS Lambda (Python 3.11) |
Framework | AWS Lambda Powertools |
Routing | APIGatewayRestResolver |
Validation | Pydantic |
Database | DynamoDB |
Local Testing | LocalStack |
IaC | AWS SAM |
ecommerce-orders/
├── app.py # Lambda handler + routing
├── models.py # Pydantic data models
├── requirements.txt
├── utils/
│ ├── db.py # DynamoDB helpers
│ └── features.py # Feature flags
├── template.yaml # AWS SAM template
└── README.md
Make sure you have the following installed:
- 🐍 Python 3.11+
- 🐳 Docker (for LocalStack)
- 📦 AWS CLI
- 📦 AWS SAM CLI → https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html
- 📦 LocalStack → https://docs.localstack.cloud/getting-started/installation/
Install Python dependencies:
pip install -r requirements.txt
localstack start -d
awslocal dynamodb create-table --table-name Orders --attribute-definitions AttributeName=order_id,AttributeType=S --key-schema AttributeName=order_id,KeyType=HASH --billing-mode PAY_PER_REQUEST
sam build
AWS_ENDPOINT_URL=http://localhost:4566 sam deploy --guided --parameter-overrides "Environment=local"
Creates an order.
curl -X POST http://localhost:4566/restapis/{api_id}/local/_user_request_/order -H "Content-Type: application/json" -d '{"customer": "John Doe", "items": ["item1", "item2"]}'
Fetch a specific order:
curl http://localhost:4566/restapis/{api_id}/local/_user_request_/order/{order_id}
These are used internally by Powertools:
POWERTOOLS_SERVICE_NAME=orders
POWERTOOLS_METRICS_NAMESPACE=EcommerceApp
Logger
: structured loggingTracer
: distributed tracing via AWS X-RayMetrics
: custom CloudWatch metricsIdempotency
: safely retryable functionsFeature Flags
: staged rollouts
- SQS integration for async processing
- Add JWT-based auth (Cognito/JWT + Lambda Authorizer)
- Pagination and filters on
GET /order
- GitHub Actions CI/CD
MIT License - feel free to fork, improve, and reuse!