I run Memos, an open-source Markdown notes app, on Amazon ECS Fargate. I wanted a setup that keeps working when something breaks, so I built it across two Availability Zones and wrote all of it as modular Terraform, with the state kept in S3.
From the browser to PostgreSQL
Requests hit an Application Load Balancer with AWS WAF in front of it. The WAF uses AWS’s IP reputation, known bad inputs and common rule sets, plus a rate limit for each IP address. Behind it, the tasks sit in private subnets in both zones and share a Multi-AZ RDS PostgreSQL 16 database. If the primary goes down, a standby in the other zone takes over on its own within a couple of minutes. I added VPC endpoints for ECR, CloudWatch Logs, Secrets Manager and S3 so most AWS traffic stays off the internet, and I kept the NAT gateways for calls to anything outside AWS.
From a commit to a new release
Before each release, a temporary ECS task sets up the database and puts the app credentials into AWS Secrets Manager. Two GitHub Actions workflows handle the rest, one for Terraform and one for the app. They sign in to AWS with OIDC, so there are no long-lived keys sitting in GitHub, and the CI role only trusts my Memos repository. Every image tag is immutable, and each release gets its own task definition pinned to the image digest. The deploy script then checks that every running task is using that exact image. If a release goes wrong, rolling back just means pointing the service at the previous revision.
Knowing when something is wrong
Five CloudWatch alarms watch for load balancer and target errors, too few healthy targets, high database CPU and low database storage. The service scales between two and four tasks when CPU or memory passes 70 percent. Terraform validation and TFLint have to pass before anything runs, while Trivy and Checkov report findings without blocking the pipeline.
What went wrong along the way
To test it properly, I rebuilt the whole stack from nothing, checked the app worked, then destroyed everything and made sure the AWS account was empty. That turned up plenty. The Free plan refused a seven day database backup retention, so it is one day now. Secrets Manager kept old secret names reserved after a destroy, so I switched off the recovery window to let rebuilds work first time. The CI role was missing a few CloudWatch, WAF and EC2 permissions, and I only found each one when a run failed.
The biggest mistake was destroying my bootstrap stack while the main stack was still running. That deleted the state bucket and the CI role, and the next apply built a second VPC next to the first. I listed everything by tag, deleted the leftover network in dependency order and rebuilt from empty. The lesson is simple: never destroy bootstrap while anything depends on it.