Abhinav C

Moving EC2 to ECS without anyone noticing

The best migration is one where the only people who notice are the ones reading the bill.

This is the order that has worked for me when moving long-lived EC2 workloads onto ECS with Docker and CloudFormation.

Containerize honestly

The first Dockerfile always exposes what the AMI was hiding: a config file someone edited by hand, a cron job, a log that only exists on local disk. Write each one down. Logs go to stdout. Config comes from environment variables or Parameter Store. Anything stateful moves out of the container.

Keep the same front door

Keep the existing load balancer. Register the ECS service in a second target group, then shift traffic with weighted forwarding on the listener: 10%, then 50%, then 100%. Rolling back is changing one number.

Health checks that tell the truth

A health check that returns 200 while the database is down is lying to your load balancer. Check the dependencies that make the service useful, and give slow starters a grace period long enough to wake up.

Everything in the template

Task definitions, services, alarms and scaling policies all live in CloudFormation. If it was clicked together in the console, it doesn’t exist for the next person.

When we finished, nobody sent a congratulations email. That’s how you know it went well.

Filed under: migrations, invisible on purpose.

More writing