CS Fundamentals Trainer · Guides

AWS for a React and Django application: the services, how they fit together and the usual mistakes

A map of the AWS services a typical React frontend and Django API use and why: S3 and CloudFront for the static app, a load balancer with ECS Fargate (or Elastic Beanstalk or EC2) for Django, RDS PostgreSQL, ElastiCache, SQS, S3 uploads with presigned URLs, VPC networking and security groups, IAM roles, secrets, CloudWatch, a deployment pipeline and the cost and security traps that catch teams out.

7 min read

AWS has hundreds of services, but a web product built with React and Django uses a small, predictable set. This guide walks through that set from the user's browser inward, says what each piece is for, and lists the decisions and mistakes that matter in practice. Exact limits and prices change, so check the current documentation before relying on a number.

The shape of the system

Browser --> Route 53 (DNS) --> CloudFront (CDN, TLS)
                                 |-- /         --> S3 bucket with the built React app
                                 |-- /api/*    --> Application Load Balancer --> Django containers (ECS Fargate)
                                                                                   |--> RDS PostgreSQL
                                                                                   |--> ElastiCache Redis (cache, sessions)
                                                                                   |--> SQS or Redis --> Celery workers
                                                                                   |--> S3 (user uploads)

The frontend: S3 and CloudFront

A React single-page app is a set of static files after npm run build. Store them in an S3 bucket that is not public, and serve them through CloudFront, AWS's content delivery network, which caches them at edge locations near users and terminates HTTPS with a free certificate from ACM (AWS Certificate Manager; certificates for CloudFront must be in us-east-1). An origin access control lets only CloudFront read the bucket.

Points that matter:

The backend: where Django runs

Options, from most managed to least:

OptionWhat you manageGood for
App Runner or Elastic Beanstalkthe application and configurationsmall teams, quick start
ECS on Fargatecontainer images and task definitions; no serversmost production APIs
EC2 instancesthe operating system, patching, scalingspecial needs, or very cost-sensitive steady load
EKS (Kubernetes)a clusterorganisations already standardised on Kubernetes
Lambdafunctionsevent handlers, cron jobs; a full Django app fits awkwardly

A common choice is ECS Fargate: build a Docker image with Gunicorn (or Uvicorn for ASGI), push it to ECR (the container registry), and run it as an ECS service with several tasks behind an Application Load Balancer (ALB). The ALB checks a health endpoint, spreads requests, and drains tasks during deploys. Auto scaling adds tasks on CPU or request count.

Run database migrations as a separate one-off task before the new version takes traffic, not at container start, so that ten tasks do not race to migrate. Keep migrations compatible with the version still running (add columns first, remove later).

Celery workers run as another ECS service from the same image with a different command. A scheduled job (celery beat, or EventBridge Scheduler starting a task) handles periodic work.

Data: RDS, ElastiCache and S3

Networking: VPC, subnets and security groups

Everything runs in a VPC (your private network in AWS), spread across at least two availability zones:

Private resources reach the internet (to call an email API, say) through a NAT gateway, which is charged per hour and per gigabyte. VPC endpoints for S3, ECR and other AWS services keep that traffic inside AWS and often cut the NAT bill noticeably.

Identity and secrets

Observability

Deployment pipeline and infrastructure as code

A typical pipeline: run tests and linters, build the React app and upload it to S3, build the Django image and push it to ECR, run migrations as a one-off task, update the ECS service (a rolling or blue/green deploy that the ALB health checks protect), then invalidate CloudFront.

Describe the infrastructure as code with Terraform, AWS CDK or CloudFormation, so environments are reproducible, changes are reviewed, and a staging environment really matches production.

Security checklist

  1. No public S3 buckets unless intended; Block Public Access on at account level.
  2. RDS and Redis in private subnets, reachable only from the app's security group; encryption at rest on.
  3. HTTPS everywhere (ACM certificates), HTTP redirected; HSTS from Django or CloudFront.
  4. AWS WAF on CloudFront or the ALB for rate limiting and common attack patterns.
  5. CloudTrail on, and alerts on root sign-in and IAM changes.
  6. Django ALLOWED_HOSTS, SECURE_PROXY_SSL_HEADER (the ALB terminates TLS) and secure cookie settings set for the real domain.

Cost traps

Sources

Practise this topic: DevOps & Cloud DevOps & Cloud › Cloud

More guides