You rarely run a Task manually. A manually-run Task is a one-shot job — it runs and exits. For long-running workloads (APIs, workers, servers), you define a Service.
"Keep N Running"
A Service has one primary job: maintain a Desired Count of healthy tasks at all times.
- You declare: "I want 5 tasks running."
- ECS starts 5 tasks.
- One crashes at 3 AM. ECS detects the failure within seconds and launches a replacement — no human intervention required.
- You deploy a new Task Definition revision. The Service performs a rolling update, replacing old tasks with new ones while keeping the total count stable.
Deployment Strategies
ECS Services support two deployment strategies that control how updates are rolled out:
Rolling Update (default):
ECS replaces tasks incrementally. Two parameters control the pace:
- minimumHealthyPercent: The floor. If set to 50%, ECS can terminate half the tasks before replacements are healthy. Lower = faster deploys, higher risk.
- maximumPercent: The ceiling. If set to 200%, ECS can run double the desired count during a deploy (old + new tasks simultaneously). Higher = safer deploys, higher cost.
Blue/Green (via CodeDeploy):
ECS creates an entirely new set of tasks (green), shifts traffic from the ALB to green, and only terminates the old set (blue) after a configurable bake time. This enables instant rollback by shifting traffic back to blue. This is the preferred strategy for zero-downtime deployments of critical services.
Load Balancing Integration
The Service is the component that registers tasks with the Application Load Balancer (ALB). The workflow is automatic:
- Service launches a new task. The task gets IP
10.0.1.50via its ENI. - Service calls the ALB API: "Add
10.0.1.50:8080to Target Groupmy-api-tg." - ALB runs health checks against the new task.
- Once healthy, the ALB starts routing traffic to it.
- When the task stops, the Service triggers connection draining — the ALB stops sending new requests to that task and waits for in-flight requests to complete before deregistering it.
This entire lifecycle is managed by ECS with zero manual steps.