This repository contains the complete AWS Infrastructure-as-Code (CDK in Python) required to deploy and scale a mission-critical, high-traffic async Python microservice (FastAPI/Litestar).
This infrastructure is battle-tested in production, independently handling over 3.5 Million HTTP requests per week.
This single ECS Application Load Balancer is the unified backend for multiple enterprise domains, securely routing and absorbing massive external traffic before it reaches the containerized application.
(Please place your Cloudflare screenshot here in the
/imagesfolder ascloudflare_ishain.png)
(Please place your Cloudflare screenshot here in the
/imagesfolder ascloudflare_sadhguru.png)
The backend application is a modern, async-first FastAPI/Litestar API utilizing MongoDB. Because it relies heavily on non-blocking I/O, the infrastructure was architected to securely scale and manage connection pooling at an enterprise level.
- VPC & Networking: Isolated subnets (Private with Egress) for ECS instances to ensure no direct internet exposure.
- Application Load Balancer (ALB): Internet-facing ALB acting as the single point of ingress. Cloudflare DNS CNAME records point directly to this ALB.
- ECS Cluster & EC2 Auto Scaling: Containerized deployment running on ECS-Optimized Amazon Linux 2 instances via an ASG Capacity Provider.
- Zero-Trust Security: No SSH ports are open. EC2 access is strictly managed via AWS Systems Manager (SSM).
- Secrets Management: AWS Secrets Manager injects secure credentials directly into the ECS task definition at runtime (
aws-msk-config-providerstyle), completely eliminating hardcoded keys. - Observability: CloudWatch Log Groups for centralized container logging and ELK Stack for log aggregation.
- CI/CD Pipeline: Both the FastAPI application deployments and the CDK infrastructure state are fully automated and managed centrally via GitHub Actions.
- Infrastructure as Code (IaC): AWS CDK (Python)
- CI/CD Pipeline: GitHub Actions
- Compute Layer: Amazon ECS (Elastic Container Service) on EC2
- Networking: AWS Application Load Balancer (ALB), Route 53, Cloudflare
- Application Layer: Python 3.10, Litestar/FastAPI, Pymongo (Async)
- Database: MongoDB Atlas
- Python 3.8+
- AWS CLI configured
- AWS CDK CLI installed (
npm install -g aws-cdk)
# Create and activate virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Synthesize the CloudFormation template
cdk synth
# Deploy to your AWS environment
cdk deploy
