Back to work
// comparison
EC2 + CodeDeploy vs ECS Fargate: how I choose
When I reach for EC2 + CodeDeploy on an Auto Scaling Group, and when I reach for ECS Fargate — based on real projects.
Both of these are patterns I run in production, so this isn't about which one is "modern". EC2 + CodeDeploy on an Auto Scaling Group and ECS Fargate each win in different places, and the deciding factor is usually ownership and fit — how much of the host I want to manage — not fashion. Here's where I land, and why.
Side by side
| EC2 + CodeDeploy (ASG) | ECS Fargate | |
|---|---|---|
| Deploy unit | An app revision pushed onto the EC2 instances in the Auto Scaling Group; CodeDeploy runs lifecycle hooks on each host. MailCheck ships a Rails bundle this way. | A container image referenced by a task definition, run as a service; each deploy launches new tasks from a new image tag. |
| Scaling | The Auto Scaling Group adds or removes EC2 instances; you also size the app processes that run on each host. | Service desired-count and target tracking scale the number of tasks; AWS manages the underlying capacity. |
| Patching / OS ownership | I own the OS — AMI, packages and patching. MailCheck's hosts are provisioned with Ansible so the baseline stays repeatable. | No OS to patch. AWS manages the host; I own only what's inside the container image. |
| Operational ownership | The instance lifecycle — launch → deploy → health → traffic — is mine to wire up. On MailCheck that surfaced as real work: holding new instances out of the pool until the revision was deployed and healthy, tuning the target-group health check so rollback fired only on genuinely bad releases, and keeping disks bounded with revision cleanup and log rotation. See MailCheck's challenges. | AWS owns the host and much of that lifecycle: a task is added behind the ALB only once it passes its health check, failed deploys stay on the old task set, and there is no host disk to keep clean. |
| Cost model | Pay for the running instances whether busy or idle — a good fit when load is steady and the box stays well used. | Pay per task for the vCPU and memory it requests, per second — a good fit for spiky or low-baseline load, with no idle host to amortise. |
| Rollback | CodeDeploy supports automatic rollback on failed health checks, returning to the last good revision. | ECS keeps the previous task set running until the new one is healthy, then shifts over; a failed deploy stays on the old tasks. |
| Secrets | Injected at deploy or boot rather than baked into the repo or the AMI. | Secrets Manager entries referenced by the task definition and injected at task start (Sentinel, CareIntake, PetCare). |
| Logs | App and CodeDeploy agent logs sit on the host; ship them to CloudWatch with an agent when you want them centralised. | The awslogs driver streams container stdout/stderr straight to CloudWatch Logs. |
| When I'd pick it | A single long-lived app with steady load where I want host control and a familiar Bitbucket → CodeDeploy flow (MailCheck). | New services where I don't want to own servers — Bitbucket OIDC → ECR → ECS, RDS in private subnets, Secrets Manager (Sentinel, CareIntake, PetCare). |
My rule of thumb
- Reach for ECS Fargate by default on greenfield services — less to own, and the OIDC → ECR → ECS path is clean (Sentinel, CareIntake, PetCare).
- Stay on EC2 + CodeDeploy when there's an existing host-shaped app, steady load, or something the OS needs to do that a container makes awkward (MailCheck).
- Don't migrate a working EC2 + ASG app to Fargate just to be on containers — move when host ownership is actually costing you time.
- Whichever I pick, deploys stay minimal-downtime by design: CodeDeploy health checks on one side, ECS healthy-before-shift on the other.