
From Supabase to S3: Deploying ReadEase on AWS
This article shares the journey of deploying ReadEase on AWS using an Application Load Balancer, private subnets, ECS Fargate, RDS for PostgreSQL, and Amazon S3. It covers architecture decisions, real deployment issues, the Terraform workflow, and secure ECS deployments with GitHub Actions and OIDC.
ReadEase is an adaptive reading platform designed for children who experience reading difficulties. The application consists of a React frontend, a NestJS backend, a FastAPI machine learning service, Redis for short-lived state, and PostgreSQL for transactional data. This article documents how I deployed ReadEase on AWS with Terraform, from selecting the architecture to running database migrations, validating the health endpoint, and testing media operations on Amazon S3.
The goal was to create a reproducible demo environment that was close enough to a production system to demonstrate cloud engineering skills, while keeping cost and complexity appropriate for a portfolio project. This is therefore not a production-ready architecture: the workloads are Single-AZ, the Application Load Balancer currently serves HTTP, and the application does not yet have a custom domain.
Architecture overview
Users enter through an Internet Gateway and reach an Application Load Balancer. The ALB routes frontend requests to the frontend ECS service and API or WebSocket requests to the backend ECS service. Both ECS services run in a private application subnet without public IP addresses.

The ALB does not route through the NAT Gateway. Inbound traffic follows
Internet Gateway -> ALB -> ECS , while the NAT Gateway is used only for outbound Internet access from the private application subnet.
Why are there two private DB subnets but only one RDS instance?
An RDS DB subnet group must contain subnets in at least two Availability Zones. Terraform therefore creates
Private DB A and Private DB B and places both in one DB subnet group. However, multi_az = false means AWS places only one active RDS instance in one subnet. The other subnet satisfies the DB subnet group requirement; it does not contain a standby database.This is easy to misrepresent in an architecture diagram. Both subnets should be visible, but the diagram should show only one active RDS instance.
Separate frontend and backend ECS services
The frontend and backend both run on ECS Fargate, but as independent services:
- The frontend service runs a React production build behind Nginx on port
80.
- The backend service runs three containers in the same task:
- NestJS API on port
3000.
- FastAPI ML on port
8000, reachable internally through127.0.0.1.
- Redis on port
6379for OTPs and short-lived application state.
The backend container starts only after the Redis and ML containers pass their health checks. Redis and FastAPI are not exposed to the Internet; they share the backend task's network namespace and communicate over localhost.
The ALB uses the following routing rules:
Path | ECS target |
|---|---|
/* | Frontend service on port 80 |
/api/* | Backend service on port 3000 |
/tracking and /tracking/* | Backend WebSocket endpoint on port 3000 |
This separation gives the frontend and backend independent deployment lifecycles while keeping the operating model simpler than combining unrelated processes in one container.
Database and migrations
Terraform creates an RDS for PostgreSQL 16 instance in the private DB subnet group with the following configuration:
-
publicly_accessible = false.
-
multi_az = false.
- Encryption at rest enabled.
- An AWS-managed master password stored in Secrets Manager.
- A database security group that accepts port
5432only from the backend security group.
Database migrations do not run inside the production container that serves requests. Instead, I run an ECS one-off task in the private application subnet using the same backend task definition and security group:
$cluster = terraform output -raw ecs_cluster_name
$taskDefinition = terraform output -raw backend_task_definition_arn
$subnet = terraform output -raw private_app_subnet_id
$securityGroup = terraform output -raw backend_security_group_id
$network = "awsvpcConfiguration={subnets=[$subnet],securityGroups=[$securityGroup],assignPublicIp=DISABLED}"
aws ecs run-task `
--cluster $cluster `
--launch-type FARGATE `
--task-definition $taskDefinition `
--network-configuration $network `
--overrides '{"containerOverrides":[{"name":"backend","command":["npm","run","migration:run"]}]}'The migration task successfully applied all 19 TypeORM migrations and exited with code
0 .The backend connects to RDS using TLS. For this demo,
DB_SSL_REJECT_UNAUTHORIZED=false simplifies packaging because the RDS CA bundle is not included in the image. A production deployment should include the AWS RDS CA bundle and enable certificate verification.Moving storage from Supabase to Amazon S3
A real issue surfaced immediately after the first deployment: creating reading content returned HTTP
500 because the backend still called Supabase Storage, but no Supabase credentials were configured in the AWS environment.Terraform had already created a private S3 media bucket and granted the backend task role access to it. The most coherent fix was therefore to migrate the storage adapter to S3 instead of making the bucket public or reintroducing an external storage dependency.
StorageService now prefers S3 whenever S3_MEDIA_BUCKET is set and retains Supabase as a fallback for older environments. Objects are uploaded with AES256 server-side encryption. Because the bucket remains private, the backend returns a stable same-origin proxy URL:/api/v1/upload/file/content?key=stories/...When the frontend reads a story, the request goes through the backend. The backend retrieves the object from S3 using its ECS task role and returns the content to the browser. This keeps the bucket private and avoids storing short-lived presigned URLs in PostgreSQL.
I verified the adapter and IAM permissions with an ECS one-off smoke test:
- Upload a small text file to S3.
- Download the object.
- Compare the downloaded content with the original input.
- Delete the test object.
The task logged
S3_SMOKE_OK , and all three containers exited with code 0 .Terraform workflow
The Terraform configuration is organized by ownership boundary: networking, security, ECR, logs, secrets, S3, RDS, IAM, ALB, and ECS.
deploy_services defaults to false , allowing the platform and ECR repositories to be created before application images exist.The core workflow is:
terraform init
terraform fmt -check
terraform validate
terraform plan -out readease.tfplan
terraform apply readease.tfplanAfter pushing the initial images, I set
deploy_services = true and ran a second plan and apply to create the frontend and backend ECS services.Image variables are separated into
frontend_image_tag , backend_image_tag , and ml_image_tag . This prevents a backend-only release from accidentally pointing the frontend or ML container to a nonexistent tag.The most important operational rule is to review the Terraform plan before every apply. The S3 rollout produced:
1 to add, 1 to change, 1 to destroyThe destroy action represented replacement of the old task definition revision, not deletion of the ECS service or application data. The VPC, subnets, RDS instance, S3 bucket, IAM roles, and frontend service were unchanged. After the apply, the final plan reported:
No changes. Your infrastructure matches the configuration.CI/CD with GitHub Actions and OIDC
The original repository workflow attempted to deploy to a VPS over SSH and failed because
VPS_HOST was not configured. That workflow no longer matched the AWS architecture, so I replaced it with an ECS deployment pipeline.The new pipeline uses GitHub's OIDC token to assume a least-privilege AWS IAM role. No long-lived AWS access key is stored in GitHub Secrets. The IAM trust policy accepts tokens only from
ngoNguyenTruongAn/ReadEase-Backend on the main branch.For each push to
main , the pipeline:- Runs backend linting and unit tests plus ML service tests.
- Builds the backend and ML images.
- Pushes immutable images to ECR using the Git commit SHA as the tag.
- Registers a new backend ECS task definition revision.
- Runs database migrations in an ECS one-off task.
- Updates the backend ECS service and waits for it to become stable.
- Calls the public health endpoint through the ALB.
The first complete run succeeded and deployed backend task definition revision
4 . The backend test suite reported 222 passing tests, ECS reported zero failed tasks, and the final health check returned HTTP 200 .Terraform manages the infrastructure baseline, while GitHub Actions owns application task definition revisions. The backend ECS service uses a lifecycle rule to ignore task definition changes made by the deployment pipeline, preventing a later Terraform plan from rolling the application back to an older revision.
Verification results
The final deployment passed the following checks:
- Frontend ALB target:
healthy.
- Backend ALB target:
healthy.
-
GET /api/v1/health: HTTP200.
- PostgreSQL connectivity: healthy.
- All 19 database migrations completed.
- S3 upload, download, and delete smoke test: passed.
- Full backend test suite: 222 tests passed.
- GitHub Actions OIDC deployment: passed.
- Terraform validation: passed.
- Final Terraform plan: no changes.
The current application endpoint is:
http://readease-demo-alb-1388515170.ap-southeast-1.elb.amazonaws.comWhat would change for production?
The current architecture is appropriate for a demo and portfolio, but it should not be used for real children's data. The next production steps would include:
- Add a custom domain and an ACM certificate, then move the ALB to HTTPS.
- Run ECS workloads and RDS across multiple Availability Zones.
- Replace the ephemeral Redis sidecar with a managed service that provides persistence and failover.
- Configure production SMTP instead of logging OTPs in development mode.
- Configure the Gemini API key if all AI-assisted features are required.
- Add CloudWatch alarms, dashboards, tracing, and alerting.
- Move Terraform state to a protected remote backend with state locking.
- Add deployment approvals and separate staging and production environments.
- Review IAM, retention, backups, and data privacy before storing real user data.
Conclusion
The most valuable part of this deployment was not simply creating a VPC or an ECS cluster. The harder task was connecting the components into a verifiable system: private subnet egress through a NAT Gateway, ECS-to-RDS communication over TLS, task-role access to private S3 objects, independent database migrations, and correct ALB routing to two services.
ReadEase now runs on AWS with separate frontend and backend services, a private database, private media storage on S3, Terraform-managed infrastructure, and an OIDC-based GitHub Actions deployment pipeline. For an academic or portfolio project, this provides a solid foundation for adding HTTPS, Multi-AZ availability, stronger observability, and production-grade operational controls.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article