Migrating a Legacy Monolith to Serverless on AWS

Published: (December 10, 2025 at 09:40 AM EST)
1 min read
Source: Dev.to

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

RouteDescription
/productsMigrated Route
/products/restockEnhanced (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 curl for 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

ScenarioEndpointDescription
1/usersLegacy route
2/productsMigrated route
3/products/restockChaos route (POST)

Example request for Scenario 3:

curl -X POST /products/restock

Troubleshooting Guide

IssueCause
502 Bad GatewayAPI Gateway couldn’t reach the EC2 instance.
400 Bad RequestPayload version mismatch.
500 Internal Server ErrorExpected behavior for chaos testing.
405 Method Not AllowedUsing 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
Back to Blog

Related posts

Read more »