The signature and its nearby causes#
The new deployment's tasks are running and healthy, but the old deployment keeps its tasks and the service never reports service (SERVICE) has reached a steady state. The 2023 developer guide gives the event ECS sends when protection is the reason:
service (service-name) was unable to reach steady state because task set (taskSet-ID) was unable to scale in. Reason: The number of protected tasks are more than the desired count of tasks.
AWS may word the current event differently; look for a service event that mentions protected tasks. Three causes keep old tasks alive, and they need different responses. Service event messages · Task scale-in protection
- Protection. In a rolling update, ECS creates new tasks but does not stop old ones until
protectionEnabledis unset or expires. Protection lasts 2 hours by default and can be set from 1 minute to 2,880 minutes (48 hours). Each call that sets it again resets the expiry, so a worker that refreshes its protection while it has work can hold a task indefinitely. UpdateTaskProtection - Deployment settings. If
minimumHealthyPercentandmaximumPercentleave the scheduler no room to stop or start a task, the service says so in an event that names the deployment configuration. DeploymentConfiguration - New tasks not yet healthy. The scheduler keeps old tasks to satisfy
minimumHealthyPercentwhile new tasks fail to start or fail health checks. Then the new deployment'sfailedTasksrises or its tasks stop, which is a separate question about deployments stuck in progress.
Read protection on the old deployment's tasks#
Start from the service: its deployments, their counts, and the recent events. startedBy on each task holds the ID of the deployment that started it, so the old deployment's ID finds its tasks. Deployment fields · Task fields
aws ecs describe-services \
--profile PROFILE --region REGION --cluster CLUSTER --services SERVICE \
--query 'services[0].{desired:desiredCount,maxPercent:deploymentConfiguration.maximumPercent,minPercent:deploymentConfiguration.minimumHealthyPercent,deployments:deployments[].{id:id,status:status,definition:taskDefinition,desired:desiredCount,running:runningCount,failed:failedTasks,rollout:rolloutState},events:events[:15].[createdAt,message]}' \
--output json --no-cli-pager
aws ecs list-tasks \
--profile PROFILE --region REGION --cluster CLUSTER \
--started-by OLD_DEPLOYMENT_ID \
--query 'taskArns' --output json --no-cli-pager
--started-by must be the only filter on list-tasks. Then read protection for those tasks, up to 100 per call. list-tasks · get-task-protection
aws ecs get-task-protection \
--profile PROFILE --region REGION --cluster CLUSTER \
--tasks TASK_ARN_1 TASK_ARN_2 TASK_ARN_3 \
--query '{protected:protectedTasks[].{task:taskArn,enabled:protectionEnabled,expires:expirationDate},failures:failures[].{arn:arn,reason:reason}}' \
--output json --no-cli-pager
protectionEnabled is true for a protected task, and expirationDate is when the protection lapses. Read it twice, a few minutes apart. An expiry that moves later between readings means something is refreshing the protection. Protection applies only to service tasks; for a standalone task the API returns a TASK_NOT_VALID failure. ProtectedTask · GetTaskProtection
What each result means#
| Old tasks | Service events | Most likely cause | What to do |
|---|---|---|---|
| Protected, and the expiry stays fixed | Protected tasks event | Protection that will lapse | Wait for expirationDate, or clear protection on tasks you know are idle |
| Protected, and the expiry keeps moving | Protected tasks event | A worker or controller renewing protection | Find what calls the endpoint or the API, and whether its work has finished |
| Not protected | Deployment configuration event | minimumHealthyPercent and maximumPercent | Change the pair so the scheduler can stop or start at least one task |
| Not protected | No such event; new deployment's failedTasks above zero | New tasks not becoming healthy | Read the new tasks' stop codes |
The protection can come from two places. The task can set it from inside the container through the agent endpoint $ECS_AGENT_URI/task-protection/v1/state, which needs ecs:UpdateTaskProtection in the task role, or an external controller can call UpdateTaskProtection. If the task role holds that permission, the application is the first place to look. Scale-in protection endpoint · Task scale-in protection
An illustrative deployment, two outcomes#
This fixture is fictional. The queue worker checkout runs 4 tasks with maximumPercent 200 and minimumHealthyPercent 100. Deployment ecs-svc/2211 for checkout:42 started at 14:00 and its 4 tasks were healthy by 14:04.
| Time | Record | Value |
|---|---|---|
| 14:04 | Deployment ecs-svc/2211 | Running 4, failedTasks 0 |
| 14:04 | Deployment ecs-svc/1987 (old) | Running 4 |
| 14:10 | Service event | The protected tasks event |
| 14:12 | get-task-protection on the old tasks | All 4 protectionEnabled true, expiries between 14:40 and 15:55 |
| 14:22 | get-task-protection again | Three expiries unchanged; the fourth moved from 15:55 to 16:20 |
In this outcome, the release is not the problem. Each old worker sets protection while it processes a job, with a 120-minute expiry, and three of them will finish and lapse within the hour. The fourth refreshes protection each time it takes a new message, so it would hold the deployment for as long as messages keep arriving. The code that renews protection is the place to change: it should stop renewing once the worker has no job in hand.
In the second outcome, the 14:12 reading shows every old task with protectionEnabled false, and the events at 14:10 say that the deployment configuration prevents the scheduler from stopping or starting tasks. Protection is not involved. The deployment settings are, and waiting would not help.
What to change, and how to confirm#
AWS gives three responses to the protected tasks event: wait for protection to expire, clear protection on tasks you know can stop, or raise the desired count above the number of protected tasks. Clearing protection is a change: update-task-protection with --no-protection-enabled on a named task ends its protection and makes it eligible for the deployment to stop, with any work in progress. Clear it only for tasks whose work you have confirmed is done or safe to lose. Service event messages · update-task-protection
For the longer term, set expiresInMinutes to how long a unit of work takes. AWS notes that a protection period longer than necessary adds cost and delays the deployment of new tasks. Its 2023 guide also notes that a CloudFormation stack update times out after 3 hours, so protection held longer than that can fail the stack update and roll it back. Task scale-in protection
On the next deployment, read get-task-protection on the old tasks once the new tasks are healthy. Each expiry should be fixed and near, the old deployment's running count should fall as protection lapses, and the service should report a steady state.
Where the reading stops#
get-task-protection shows the current state. It does not say who set protection or when, and a task that lost protection and stopped has left the listing. The service keeps only its 100 most recent events, so a long wait can push the protected tasks event out of describe-services. Service fields
Protection also blocks Service Auto Scaling scale-in, so a service that scaled out during the deployment can stay above its intended size after the rollout for the same reason. For the general method of sorting what stopped and why, read the signature table and the stop code guide; the auto scaling guide covers count changes during a rollout.
Questions#
How long does ECS task scale-in protection last?
Two hours by default. A caller can set from 1 minute to 2,880 minutes (48 hours), and each call that sets protection again resets the expiry, so a task can stay protected for as long as something keeps renewing it.
Does task protection stop a rolling deployment from finishing?
It delays it. ECS starts the new tasks but does not stop protected old tasks until their protection is cleared or expires, and the service reports that it cannot reach a steady state.
How do I find which ECS tasks are protected?
List the old deployment's tasks with list-tasks --started-by, then call get-task-protection with up to 100 task IDs. Each entry reports protectionEnabled and expirationDate.