---
title: "Which ECS task stops came from your deployment? Read the stop code | Proofline"
description: "During a rollout, ECS stops tasks for several reasons at once: new tasks fail, old ones retire, Spot capacity is reclaimed and scaling trims the count."
url: https://proofline.sh/learn/ecs-task-stop-codes/
---

[Learning center](/learn/)

# Which ECS task stops came from your deployment? Read the stop code

During a rollout, ECS stops tasks for several reasons at once: new tasks fail, old ones retire, Spot capacity is reclaimed and scaling trims the count. Sort the stopped tasks by two fields, stopCode and the deployment ID in startedBy, before you read any reason text. Only failures among the new deployment's tasks are evidence against the release.

Deployment failures The Proofline team November 22, 2026 6 min read

## Seven codes, one question each

Every stopped task carries a `stopCode` from a fixed list and a free-text `stoppedReason` with the details. AWS says the reason text can change between releases, so the code is the field to sort and alert on. [Task fields](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Task.html) · [Stopped-task message updates](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/stopped-tasks-error-messages-updates.html)

| Stop code | What stopped the task | Next read |
| --- | --- | --- |
| `TaskFailedToStart` | The task failed before its essential container ran: image pull, secret, log driver, volume or network setup. | The category at the start of `stoppedReason`. There are no application logs. |
| `EssentialContainerExited` | An essential container's process exited, so ECS stopped the task. | The container's `exitCode` and its last log lines. |
| `ServiceSchedulerInitiated` | The service scheduler stopped a running task: after a failed health check, or to bring the service to its desired count, which includes removing old tasks as a rolling deployment replaces them. | The reason text says which. |
| `UserInitiated` | A `StopTask` call from a person, a pipeline or another tool. | The optional reason the caller passed, and CloudTrail for who called. |
| `SpotInterruption` | Fargate Spot reclaimed the capacity. | The task's capacity provider. Not a release failure. |
| `TerminationNotice` | A termination notice for the capacity under the task. AWS's 2023 Fargate Spot examples show this code for Spot interruptions. | The capacity provider and the host. |
| `InfrastructureHealth` | Listed in the current API; AWS's stopped-task pages hold its definition. | Those pages, then the capacity provider and host. |

The service scheduler's reason text separates its three cases. AWS documents `Task failed ELB health checks in (elb elb-name)` for a load balancer health check, `Scaling activity initiated by (deployment deployment-id)` for a task stopped to bring the service down to its desired count, and reasons such as `Host EC2 (instance id) stopped/terminated` when the instance under an EC2 task went away. A failed container health check produces a reason beginning `Task failed container health checks`. [Stopped reasons](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/stopped-task-errors.html) · [Container health checks](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_HealthCheck.html)

`UserInitiated` is easy to misread. `StopTask` accepts an optional reason that later appears in `describe-tasks`, so a deploy script or a custom scheduler can write anything there. Treat that text as a label written by the caller. [StopTask](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_StopTask.html)

## Sort the stopped tasks by deployment and code

ECS keeps stopped tasks for at least one hour after they stop. List them and describe them as soon as the rollout fails. Use a read-only profile and replace the uppercase placeholders. [Stopped task retention](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/stopped-task-errors.html) · [describe-tasks](https://docs.aws.amazon.com/cli/latest/reference/ecs/describe-tasks.html)

```
aws ecs describe-services \
  --profile PROFILE --region REGION --cluster CLUSTER --services SERVICE \
  --query 'services[0].deployments[].{id:id,status:status,definition:taskDefinition,created:createdAt}' \
  --output json --no-cli-pager

aws ecs list-tasks \
  --profile PROFILE --region REGION --cluster CLUSTER \
  --service-name SERVICE --desired-status STOPPED \
  --query 'taskArns' --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,definition:taskDefinitionArn,capacity:capacityProviderName,started:startedAt,stopping:stoppingAt,stopped:stoppedAt,code:stopCode,reason:stoppedReason,containers:containers[].{name:name,exit:exitCode,reason:reason}}' \
  --output json --no-cli-pager
```

`startedBy` holds the ECS deployment ID for a task the service started. Match it against the deployment list: the `PRIMARY` deployment is the one being rolled out, an `ACTIVE` one still has tasks being replaced. Then build a two-way count of deployment against stop code. `describe-tasks` takes up to 100 task ARNs per call. [Deployment fields](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_Deployment.html) · [DescribeTasks](https://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_DescribeTasks.html)

## What the counts say

| Pattern | Reading |
| --- | --- |
| New deployment: `TaskFailedToStart` | The release cannot start. Look for a changed image, secret, log or volume reference in the new revision. |
| New deployment: `EssentialContainerExited` | The release starts and exits. Read the exit code and the container's logs. |
| New deployment: `ServiceSchedulerInitiated`, health check reason | Running but failing its check. Read the same check's results for the old tasks before blaming the release. |
| Old deployment: `ServiceSchedulerInitiated`, `Scaling activity initiated by` | The scheduler removed old tasks to hold the desired count as new ones arrived. Expected during a rollout. |
| New deployment: `Scaling activity initiated by` | Either the desired count went down mid-rollout, or a rollback or a later deployment became primary and is retiring these tasks. Check the service events for a rollback or a new deployment, and the scaling activity for a lower desired count, in the same minutes. |
| Either deployment: `SpotInterruption` or `TerminationNotice` | Capacity reclaimed. It can stall a rollout, but it is not a verdict on the release. |
| Old deployment: health check failures in the same minutes | Something both versions share is failing, such as a dependency or the health check configuration. |

The last row is where the stop code saves the most time. A health check failure on the new tasks looks like a bad release. The same failure on old tasks that ran untouched for days points at what they share.

## An illustrative rollout

The fictional service `checkout` rolls from `checkout:31` (deployment `ecs-svc/4410`) to `checkout:32` (deployment `ecs-svc/4502`) with a desired count of 6 on a mix of Fargate and Fargate Spot. In the 20 minutes after the rollout starts, nine tasks stop:

| Deployment | Stop code | Reason begins | Tasks |
| --- | --- | --- | --- |
| `ecs-svc/4502` (new) | `ServiceSchedulerInitiated` | `Task failed ELB health checks` | 3 |
| `ecs-svc/4410` (old) | `ServiceSchedulerInitiated` | `Task failed ELB health checks` | 2 |
| `ecs-svc/4410` (old) | `ServiceSchedulerInitiated` | `Scaling activity initiated by` | 3 |
| `ecs-svc/4410` (old) | `SpotInterruption` | `Your Spot Task was interrupted.` | 1 |

Read only the new deployment's rows and `checkout:32` looks broken: three of its tasks failed health checks. The old rows change that. Two `checkout:31` tasks, which had been passing for days, failed the same check in the same window. Both versions answer the health check through code that opens a database connection, so the next read is the database and the health check path, not the diff between revisions 31 and 32. The three retired old tasks are the rollout doing its job, and the Spot interruption explains one replacement but nothing about the release.

Had the two old health check failures been absent, the same table would put the release first: new tasks failing a check the old tasks pass. The next read would be the difference between the revisions and the target health reason on the new tasks.

## Where stop codes mislead

A stop code records how a task ended, not the root cause. `EssentialContainerExited` with exit code 1 can come from a crash in new code or from a configuration value the new revision reads at startup. `ServiceSchedulerInitiated` with a health check reason only says the check failed. Stopped tasks also expire. If you arrive late, keep ECS task state change events in EventBridge for the next incident, since they carry the same stop code and reason. Finally, `startedBy` holds a deployment ID only for tasks a service started; a task launched by `RunTask` carries whatever its caller set. [Task state change events](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs_task_events.html) · [Fargate Spot interruptions](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/fargate-capacity-providers.html)

For the other layers a failed deployment can fail in, including placement failures that leave no stopped task at all, see [the signature table](/learn/aws-deployment-failure-signatures/).

## Questions

### What does ServiceSchedulerInitiated mean on an ECS task?

The service scheduler stopped a running task. The stopped reason says why: a failed load balancer or container health check, a reduction to the desired count (which includes old tasks removed during a rolling deployment), or the loss of the instance under an EC2 task.

### How do I tell which ECS deployment a stopped task belonged to?

Read the task's `startedBy` field. For a task a service started, it holds the ECS deployment ID, which you can match against the IDs in `describe-services` deployments.

### Is a SpotInterruption stop a deployment failure?

No. Fargate Spot sends a two-minute warning and a SIGTERM before reclaiming the capacity, and the service scheduler tries to start a replacement. It can slow a rollout, but it says nothing about the new revision.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [AWS deployment failure signatures: startup, placement, health, routing or scaling](/learn/aws-deployment-failure-signatures/)
    
    Deployment failures The Proofline team November 22, 2026 9 min read
    
-   ### [Fix ECS ResourceInitializationError when pulling secrets](/learn/ecs-secrets-startup-errors/)
    
    Missing secrets The Proofline team November 15, 2026 8 min read
