1.Mapping a Django or FastAPI Backend to AWS
A Django or FastAPI project already names every piece it needs: a WSGI or ASGI server, a database, a cache, a place for uploads, a task queue, somewhere for settings and secrets. Deploying to AWS is mapping each of those to a managed service and deciding what the process boundaries are. Nothing about the application changes shape — what changes is who runs each piece.
Key features
- The application container is identical for web and worker processes; only the command and the scaling policy differ
- The task role gives the container its AWS permissions — no access keys are ever put in the image or the environment
- RDS Proxy pools and reuses database connections, which avoids the memory and CPU overhead of opening a new connection per request, and keeps application connections during a failover
- Secrets are read at startup from Secrets Manager or Parameter Store by ARN, so rotating one is a restart rather than a rebuild
- ALB fits a long-running Django or FastAPI service; API Gateway fits per-request Lambda handlers, and mixing the two front doors for one service rarely pays off
- stdout and stderr from the container go to CloudWatch Logs by the log driver, so the application writes JSON to stdout and configures no log files
The mapping, line by line
ALB or API Gateway in front of the same application
- Front door and edge
- Route 53 — api.example.com → ALB alias
- CloudFront — static assets and cached GETs
- ALB — TLS, health checks, path rules
- Your code — one image, two commands
- ECS web service — gunicorn / uvicorn, behind the ALB
- ECS worker service — celery worker, no load balancer
- Scheduled task — celery beat, or an EventBridge schedule
- State — none of it in your container
- RDS / Aurora PostgreSQL — DATABASES, Multi-AZ
- ElastiCache Redis — CACHES, sessions, locks
- S3 — media uploads and static files
- SQS — CELERY_BROKER_URL
- Cross-cutting
- Secrets Manager — DB password, API keys, SECRET_KEY
- IAM task role — the container's only credentials
- CloudWatch — logs from stdout, metrics, alarms
Signature
DATABASES→RDS · CACHES→ElastiCache · media→S3 · broker→SQS · secrets→Secrets Manager · logs→CloudWatch
Read the settings file as a list of services to rent: RDS for DATABASES, ElastiCache for CACHES, S3 for uploads and static, SQS for the Celery broker, Secrets Manager for anything sensitive, CloudWatch for stdout. One image runs both web and worker; the task role, not an access key, is the container's identity.