Migrating a Legacy Monolith to Serverless on AWS
Source: Dev.to
Overview
This project demonstrates how to migrate a legacy monolithic application to a serverless architecture using the Strangler Fig Pattern on AWS, leveraging:
- Terraform for Infrastructure as Code
- Python for application logic
The goal is to show how new features can be carved out from a monolith and replaced with serverless components—without breaking the existing system.
Architecture
The solution consists of the following major components:
- Legacy Monolith
- New Serverless Components
Route Behavior
| Route | Description |
|---|---|
/products | Migrated Route |
/products/restock | Enhanced (chaos) Route |
Prerequisites
Before deploying, ensure you have:
- An AWS account (Free Tier eligible)
- AWS CLI installed & configured (
aws configure) - Terraform v1.0+
- Postman or
curlfor testing
Project Structure
strangler-fig-aws-migration-demo/
Deployment Instructions
1️⃣ Initialize Terraform
# Inside the infra-terraform directory
terraform init
2️⃣ Deploy Infrastructure
terraform apply
Type yes when prompted.
Deployment takes ~2 minutes, plus an additional ~3 minutes for the EC2 instance to install dependencies and start the legacy server.
3️⃣ Retrieve the API URL
Terraform will output a value similar to:
api_url = "https://.execute-api.us-east-1.amazonaws.com"
Copy this URL for testing.
Testing Scenarios
| Scenario | Endpoint | Description |
|---|---|---|
| 1 | /users | Legacy route |
| 2 | /products | Migrated route |
| 3 | /products/restock | Chaos route (POST) |
Example request for Scenario 3:
curl -X POST /products/restock
Troubleshooting Guide
| Issue | Cause |
|---|---|
| 502 Bad Gateway | API Gateway couldn’t reach the EC2 instance. |
| 400 Bad Request | Payload version mismatch. |
| 500 Internal Server Error | Expected behavior for chaos testing. |
| 405 Method Not Allowed | Using GET on a POST‑only route. |
Re‑run the request if needed:
curl -X POST /products/restock
Cleanup (To Avoid Charges)
When finished, destroy all resources:
terraform destroy