AWS ECS: Update a Service (Deploy New Version)
Deploy a new task definition version to an ECS service using aws ecs update-service with rolling deployment and force new deployment options.
Detailed Explanation
Updating ECS Services
The aws ecs update-service command modifies an existing ECS service, most commonly to deploy a new version of a task definition. ECS performs a rolling deployment by default.
Deploy a New Task Definition
aws ecs update-service \
--cluster production-cluster \
--service api-service \
--task-definition api-task:42
This tells ECS to gradually replace running tasks with tasks using version 42 of the api-task task definition.
Force New Deployment (same version)
aws ecs update-service \
--cluster production-cluster \
--service api-service \
--force-new-deployment
Forces ECS to stop and restart all tasks even if the task definition has not changed. Useful when:
- Your container image tag (
latest) was updated - You need to pick up new secrets or config
- Tasks are in an unhealthy state
Scale the Service
aws ecs update-service \
--cluster production-cluster \
--service api-service \
--desired-count 4
Combined Deployment
aws ecs update-service \
--cluster production-cluster \
--service api-service \
--task-definition api-task:43 \
--desired-count 3 \
--force-new-deployment
Monitor the Deployment
aws ecs describe-services \
--cluster production-cluster \
--services api-service \
--query "services[0].deployments[].[status,desiredCount,runningCount,taskDefinition]" \
--output table
Example Output
---------------------------------------------------------
| DescribeServices |
+---------+------+---------+----------------------------+
| PRIMARY | 3 | 2 | arn:...:api-task:43 |
| ACTIVE | 3 | 1 | arn:...:api-task:42 |
+---------+------+---------+----------------------------+
During a rolling deployment, you will see both the PRIMARY (new) and ACTIVE (old) deployments until all tasks are replaced.
Wait for Stable
aws ecs wait services-stable \
--cluster production-cluster \
--services api-service
This blocks until the service reaches a steady state (all tasks running the latest task definition).
Use Case
Deploying new application versions to ECS Fargate or EC2 services, scaling container workloads, performing zero-downtime rolling deployments, or forcing task restarts to pick up configuration changes.