AWS ECS Notes

ECS Fargate is the AWS no-K8s path; the image and env contract are identical, ECS is just the scheduler. On EKS, prefer the Helm chart. This page covers the ECS-specific glue: the CloudFormation template, the task definition, the load balancer, RDS, and the migration one-shot.

CloudFormation template

ecs/cloudformation.yaml deploys the service on Fargate behind an Application Load Balancer, against a PostgreSQL you already run:

Every secret it reads needs no extra permission unless it is encrypted with your own KMS key; then allow the stack's task execution role to decrypt with it.

Image registry

Fargate can pull directly from ECR Public; copy the image to your own ECR for in-region pulls, immutable-tag policies and scan-on-push:

aws ecr get-login-password --region us-east-1 | \\
  docker login --username AWS --password-stdin <ACCOUNT>.dkr.ecr.us-east-1.amazonaws.com

docker pull public.ecr.aws/n6a1z5b2/db-studio:1.0.2
docker tag public.ecr.aws/n6a1z5b2/db-studio:1.0.2 <ACCOUNT>.dkr.ecr.us-east-1.amazonaws.com/simcha-db-studio:1.0.2
docker push <ACCOUNT>.dkr.ecr.us-east-1.amazonaws.com/simcha-db-studio:1.0.2

Task definition essentials

Migrations on ECS

Set MIGRATE_ON_BOOT=false on the service and gate the schema change with a one-shot task: a separate task definition on the same image with the command overridden to node dist/server/database/migrate.js. In the pipeline, aws ecs run-task, poll to a successful STOPPED exit (code 0), then update the service. This stops the deploy if the migration fails.

ALB configuration

RDS for the metadata database

Updating the service

# Mirror the new tag into your registry
docker pull public.ecr.aws/n6a1z5b2/db-studio:1.0.2
docker tag public.ecr.aws/n6a1z5b2/db-studio:1.0.2 <ACCOUNT>.dkr.ecr.us-east-1.amazonaws.com/simcha-db-studio:1.0.2
docker push <ACCOUNT>.dkr.ecr.us-east-1.amazonaws.com/simcha-db-studio:1.0.2

# Run the migration task and wait
aws ecs run-task --task-definition simcha-db-studio-migrate:<rev> ...

# Update the app service to the new task definition revision
aws ecs update-service \\
  --cluster <cluster> --service simcha-db-studio \\
  --task-definition simcha-db-studio:<new-rev> \\
  --force-new-deployment

Rolling deploys with maximumPercent: 200 / minimumHealthyPercent: 100 give zero-downtime updates.