The signature and its nearby causes#
During or just after a rollout, one of these appears:
- Tasks stop with a reason of the form
Scaling activity initiated by (deployment deployment-id). AWS's 2023 guide says this reason marks tasks stopped because the desired count of the service went down. - More tasks start than the deployment needed, or the service's
desiredCountreads differently after the rollout than before it.
Stopped task reasons · The signature table
The stopped reason records that the desired count fell. It does not record who lowered it. Three sources can change the count:
- Application Auto Scaling. A target tracking or step scaling policy changes
desiredCountfor the scalable dimensionecs:service:DesiredCount. Scale-in is turned off while an ECS deployment is in progress and resumes once it completes. Scale-out continues during a deployment unless you suspend it. Troubleshooting service auto scaling · Service auto scaling - The release or a person. The desired count is set with
CreateServiceand changed withUpdateService. A pipeline or infrastructure template that sends adesiredCountwith each deployment sets the count to whatever the template holds. Service fields - The scheduler's own replacements. ECS replaces tasks that fail health checks or exit. Those stops carry their own reasons and appear in the stop code guide.
Read the scaling activities for the deploy window#
Application Auto Scaling keeps six weeks of activities. Each one has a Cause, a Description, start and end times, and a StatusCode of Pending, InProgress, Successful, Overridden, Unfulfilled or Failed. Adding --include-not-scaled-activities also returns the times it decided not to scale, with machine-readable codes such as AlreadyAtMaxCapacity. DescribeScalingActivities · ScalingActivity · describe-scaling-activities
aws application-autoscaling describe-scaling-activities \
--profile PROFILE --region REGION --service-namespace ecs \
--scalable-dimension ecs:service:DesiredCount --resource-id service/CLUSTER/SERVICE \
--include-not-scaled-activities \
--query 'ScalingActivities[].{start:StartTime,end:EndTime,status:StatusCode,description:Description,cause:Cause,notScaled:NotScaledReasons[].Code}' \
--output json --no-cli-pager
Then read the scalable target's limits and suspension state, and the policies that act on it. ScalableTarget · SuspendedState · ScalingPolicy
aws application-autoscaling describe-scalable-targets \
--profile PROFILE --region REGION --service-namespace ecs \
--scalable-dimension ecs:service:DesiredCount --resource-ids service/CLUSTER/SERVICE \
--query 'ScalableTargets[].{min:MinCapacity,max:MaxCapacity,suspended:SuspendedState}' \
--output json --no-cli-pager
aws application-autoscaling describe-scaling-policies \
--profile PROFILE --region REGION --service-namespace ecs \
--resource-id service/CLUSTER/SERVICE \
--query 'ScalingPolicies[].{name:PolicyName,type:PolicyType,alarms:Alarms[].AlarmName}' \
--output json --no-cli-pager
Finally, line the activities up against the deployment and the stopped tasks. startedBy on each task names the deployment that started it, and each deployment carries its own desiredCount and createdAt. Deployment fields · Task fields
aws ecs describe-services \
--profile PROFILE --region REGION --cluster CLUSTER --services SERVICE \
--query 'services[0].{desired:desiredCount,running:runningCount,deployments:deployments[].{id:id,status:status,definition:taskDefinition,desired:desiredCount,running:runningCount,created:createdAt,updated:updatedAt,rollout:rolloutState}}' \
--output json --no-cli-pager
aws ecs describe-tasks \
--profile PROFILE --region REGION --cluster CLUSTER --tasks TASK_ARN_1 TASK_ARN_2 \
--query 'tasks[].{deployment:startedBy,started:startedAt,stopping:stoppingAt,code:stopCode,reason:stoppedReason,health:healthStatus}' \
--output json --no-cli-pager
The API's service events come from the service scheduler. The console's event view also shows up to 10 recent Service Auto Scaling events, so it is a quick cross-check when the activities are hard to line up. Service event messages
What each result means#
| Count change | Scaling activity at that time | Most likely source | Release involved? |
|---|---|---|---|
| Up during the rollout | Successful scale-out, cause naming a policy alarm | Application Auto Scaling | Only if the new revision raised the metric the policy tracks |
| Down during the rollout | None | UpdateService with a lower desiredCount: a pipeline, template or person | Yes, if the deployment's own update carried the count |
| Down soon after the rollout completed | Successful scale-in | Application Auto Scaling resuming scale-in | Usually not; the deployment scaled out and the policy is undoing it |
Down or up with no activity, SuspendedState all false | None | A manual or pipeline change | Check who called UpdateService |
When no activity explains the change, CloudTrail's lookup-events can find recent UpdateService calls in the Region from the last 90 days, with the identity that made them. lookup-events
A scale-out during a rollout can come from the release. If the new revision uses more CPU per request, a target tracking policy on CPU scales out, and the extra tasks are a symptom of the revision's cost, not a capacity incident. Compare the policy's metric per task for the two revisions before treating the scale-out as background.
An illustrative rollout, two outcomes#
This fictional fixture follows the service orders, normally scaled between 4 and 12 tasks by a target tracking policy on CPU. At 09:58 the pipeline deploys orders:58 as deployment ecs-svc/2211.
| Time | Record | Value |
|---|---|---|
| 09:40 | Service | desiredCount 8 after a morning scale-out |
| 09:58 | Deployment ecs-svc/2211 | Created with desiredCount 4 |
| 10:00 | Stopped tasks, ecs-svc/1987 (old) | Four tasks, reason Scaling activity initiated by (deployment ...) |
| 10:00 to 10:20 | Scaling activities | None |
In this outcome, the release lowered the count. The pipeline's service definition holds desiredCount: 4, and each deployment resets the count to 4 regardless of the policy's 8. With scale-in paused during the deployment, Application Auto Scaling did not cause the stops. Four tasks carry the morning's load, so latency rises until the policy scales out again. The fix is in the pipeline: stop sending desiredCount on update, or send the current value.
In the second outcome, the 10:00 stops are absent. Scaling activities show a Successful scale-out at 10:06 from 8 to 10, and a Successful scale-in at 10:24, after the rollout completed. The new tasks used more CPU during warm-up, the policy reacted, and scale-in resumed once the deployment finished. The count change is the scaling policy's, and the release's only part is its warm-up cost.
What to change, and how to confirm#
Each of these is a change:
- Stop the pipeline from resetting the count. Leave
desiredCountout of deployment updates for a service that Application Auto Scaling manages. AWS notes that as long as policies are active, Service Auto Scaling can change a count you set by hand, so a reset is followed by a correction, with load on too few tasks in between. Service auto scaling - Suspend scale-out during deployments, if the warm-up spike is unwanted. Set
DynamicScalingOutSuspendedon the scalable target withregister-scalable-targetbefore the deployment and clear it afterwards. A suspended target cannot react to real load during that time. SuspendedState · register-scalable-target
If the service has more running tasks than desired, unhealthy tasks still inside the health check grace period may be the ones stopped to reach the desired count. Their stop does not show that the grace period was too short. CreateService
On the next deployment, read desiredCount before and after it, and read the scaling activities for its window. The count should stay where the policy left it unless an activity explains the change, and no stopped task from the old deployment should carry a scaling reason that no activity or intended update accounts for.
Where the reading stops#
Scaling activities say what Application Auto Scaling did, not what anyone else did. The stopped reason names a deployment, which identifies the tasks, not the actor. Not-scaled activities, which you get only with --include-not-scaled-activities, explain a count that the policy left alone. Stopped tasks expire after about an hour, while activities last six weeks, so capture the tasks first. Stopped task retention
Task scale-in protection also blocks Service Auto Scaling scale-in; if old tasks stay after scale-in resumes, read the protected tasks guide.
Questions#
Does ECS service auto scaling scale in during a deployment?
No. Application Auto Scaling turns off scale-in while an ECS deployment is in progress and resumes it once the deployment completes. Scale-out continues unless you suspend it.
What does "Scaling activity initiated by (deployment ...)" mean on a stopped ECS task?
ECS stopped the task because the service's desired count went down. The reason names a deployment, not the cause of the change; read Application Auto Scaling's activities and recent UpdateService calls to find which one lowered the count.
Why does my ECS service's task count drop every time I deploy?
If no scaling activity explains the drop, check whether the deployment sends a fixed desiredCount lower than the count auto scaling had reached. Remove the count from deployment updates, or set it from the service's current value.