Learning center

ECS SpotInterruption during a deploy: Fargate Spot or the release?

A SpotInterruption stop during a deploy is reclaimed capacity; capacityProviderName, startedAt and startedBy show if the release was involved too. Fargate Spot runs tasks on spare capacity and takes it back with a two-minute warning, so a rollout on Spot can lose tasks from either deployment for reasons that have nothing to do with the new revision.

The signature and its nearby causes#

The rollout loses tasks, the running count dips, and some stopped tasks carry stop code SpotInterruption. The current API lists both SpotInterruption and TerminationNotice among the seven stop codes. AWS's 2023 Fargate guide showed a Spot interruption event with stop code TerminationNotice and the reason Your Spot Task was interrupted., and AWS's current troubleshooting page is written for SpotInterruption. Group both codes together until a task's reason says otherwise. Task fields · SpotInterruption errors · Fargate capacity providers

AWS's troubleshooting page says the error occurs when no Fargate Spot capacity is available or when Fargate takes back Spot capacity; on EC2 the equivalent is Spot Instances that are unavailable or reclaimed. That gives three readings of the same code during a deploy:

  • An old task reclaimed. A task from the previous deployment is interrupted. It explains a dip in running count, and nothing about the release.
  • A new task reclaimed after it ran. A task from the new deployment reached RUNNING and was interrupted. The interruption is still capacity, and the new revision's health is unknown from this task.
  • A new task that never got capacity. A task from the new deployment has no startedAt because no Spot capacity was available to start it. The rollout slows, and the revision is not implicated.

Stop codes that do point at the release, such as TaskFailedToStart with a reason naming the revision's image or secret, EssentialContainerExited, or a health check failure, need their own reading. The stop code guide sorts them.

Separate the stopped tasks by capacity and deployment#

List the service's stopped tasks and read, for each one, the stop code, the capacity provider that ran it, the deployment that started it, and whether it ever ran. startedBy holds the deployment ID for a service task, and capacityProviderName names the provider, such as FARGATE or FARGATE_SPOT. Stopped tasks remain visible for at least an hour. Task fields · Stopped task errors

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 TASK_ARN_3 \
  --query 'tasks[].{deployment:startedBy,definition:taskDefinitionArn,capacity:capacityProviderName,az:availabilityZone,started:startedAt,stopping:stoppingAt,stopped:stoppedAt,code:stopCode,reason:stoppedReason,containers:containers[].{name:name,exit:exitCode}}' \
  --output json --no-cli-pager

Then read the service's deployments and capacity provider strategy, so you know which deployment ID is new and how many tasks the strategy puts on Spot. A strategy's base places a minimum number of tasks on one provider first, and weight splits the rest. CapacityProviderStrategyItem · Deployment fields

aws ecs describe-services \
  --profile PROFILE --region REGION --cluster CLUSTER --services SERVICE \
  --query 'services[0].{strategy:capacityProviderStrategy,deployments:deployments[].{id:id,status:status,definition:taskDefinition,strategy:capacityProviderStrategy,running:runningCount,failed:failedTasks,rollout:rolloutState}}' \
  --output json --no-cli-pager

capacityProviderStrategy is omitted when the service uses a launch type instead of a strategy. Service fields

What each result means#

Stop codecapacitydeploymentstartedReading
SpotInterruption or TerminationNoticeFARGATE_SPOTOldSetCapacity reclaimed from the old revision; not the release
SpotInterruption or TerminationNoticeFARGATE_SPOTNewSetCapacity reclaimed from the new revision; judge the release on its other tasks
SpotInterruptionFARGATE_SPOTNewEmptyNo Spot capacity to start the task; not the release
Any other codeFARGATE or FARGATE_SPOTNewEitherRead that code; the capacity provider does not explain it

The last row matters most during an incident. When a deploy fails and some tasks were also interrupted, the interruptions are easy to blame. Read the new deployment's tasks whose stop code is not a Spot code: those are the evidence about the release.

An illustrative rollout, two outcomes#

This fictional fixture follows the service orders, with 6 tasks and a strategy of FARGATE with base 2 and FARGATE_SPOT with weight 1. Deployment ecs-svc/2211 replaces orders:57 with orders:58 at 10:00.

TimeDeploymentCapacityStop codestartedReason
10:03ecs-svc/1987 (old)FARGATE_SPOTSpotInterruption08:12Your Spot Task was interrupted.
10:04ecs-svc/2211FARGATE_SPOTSpotInterruption10:01Your Spot Task was interrupted.
10:06ecs-svc/2211FARGATE_SPOTSpotInterruptionemptyA reason about Spot capacity

In this outcome, every stop is capacity. One old task and one new task were reclaimed after they ran, and one new task could not get Spot capacity at all. The new revision's other tasks are healthy, and the rollout completes once capacity returns. Rolling back would change nothing, since the old revision runs on the same Spot capacity.

In the second outcome, the same 10:03 interruption appears, but the new deployment's other tasks stop with EssentialContainerExited and exit code 1. The interruption is incidental. The new revision starts and crashes, and its container logs are the next read; the exit code guide covers that reading.

Make interruptions cheaper, and confirm#

An interrupted task gets a two-minute warning, sent as a task state change event to EventBridge and as SIGTERM to the running task. A service then tries to launch replacement tasks on Fargate Spot if capacity is available; AWS's current page adds that Fargate does not replace Spot capacity with on-demand capacity. Fargate capacity providers · SpotInterruption errors

These are changes to consider:

  • Handle SIGTERM. The container must catch the signal to clean up. After stopTimeout, which defaults to 30 seconds and can be at most 120 seconds on Fargate, the task receives SIGKILL, which AWS warns may result in data loss or corruption. Container stop timeout · Spot termination notices
  • Keep a floor on on-demand capacity. A base on the FARGATE provider keeps that many tasks off Spot, so an interruption during a rollout cannot take the service below it. CapacityProviderStrategyItem
  • Check architecture support. The current API states that Fargate Spot supports Linux x86_64 tasks on platform version 1.3.0 or later and ARM64 tasks on 1.4.0 or later. Windows containers on Fargate don't support Fargate Spot, according to the 2023 guide. CapacityProviderStrategyItem

To confirm on the next rollout, run the same describe-tasks query on every stopped task. Each Spot-coded task should be on FARGATE_SPOT, the new deployment should have no stopped task with any other code, and rolloutState should reach COMPLETED.

Where the reading stops#

The stop code says why ECS stopped the task, not how the new revision would have behaved had it kept running. A deployment whose new tasks were all interrupted has no evidence about the release yet; wait for tasks that run long enough to pass health checks. Stopped tasks expire after about an hour, so a slow investigation should rely on task state change events retained through an EventBridge rule. Stopped-reason text can change, so key on the stop code and the capacity provider. Task state change events · The signature table

Questions#

What is the difference between SpotInterruption and TerminationNotice in ECS?

Both are stop codes in the current ECS API, and the API does not define them separately. AWS's 2023 Fargate guide showed a Spot interruption with TerminationNotice, and its current troubleshooting page covers SpotInterruption, so treat both as reclaimed capacity and read the stopped reason for detail.

How much warning does a Fargate Spot task get?

Two minutes. ECS sends a task state change event to EventBridge and SIGTERM to the task, then SIGKILL after the container's stopTimeout, which is at most 120 seconds on Fargate.

Should I roll back a deployment because tasks were interrupted on Fargate Spot?

Not on the interruptions alone. The old revision runs on the same Spot capacity. Read the new deployment's tasks with other stop codes; if there are none and the running tasks are healthy, the release has given you no reason to roll back.

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.

Start free with GitHub

Related reading