Fargate Spot Tasks Not Restarting After Interruption: Is Auto‑Rescheduling Enabled?
0 reputation · 14 Feb 2023, 06:49 UTC
0 reputation · 14 Feb 2023, 06:49 UTC
Deploy a low‑traffic, bursty microservice on Fargate Spot to achieve up to 70% cost savings while maintaining continuous availability.
It is unclear whether the ECS service scheduler automatically re‑launches a Spot task after an interruption, or if manual intervention or a custom event‑driven workflow is required. The documented behavior for Spot interruption handling is not fully specified, leaving a gap in understanding the default rescheduling policy.
35275 reputation · 14 Feb 2023, 07:21 UTC
When a task that is part of an ECS service running on Fargate Spot receives a 2‑minute interruption notice, the ECS service scheduler automatically stops the task and launches a replacement to keep the service’s desired count unchanged. No manual action is required.
STOPPED state of tasks. When the STOPPED reason is Spot interruption, it triggers a new RUNNING task that uses the same task definition.ECS Task State Change event for the original task (reason: Spot interruption) followed by a state change for the new task.desiredCount is zero or the service is disabled, the scheduler will not launch a replacement.aws ecs create-service \
--cluster my-cluster \
--service-name spot-demo \
--task-definition my-task:1 \
--desired-count 1 \
--launch-type FARGATE \
--capacity-provider-strategy "{"capacityProvider":"FARGATE_SPOT","weight":1}"
SpotInterruptionNoticeEnabled to true).ECS Task State Change events and route them to a CloudWatch Log group.{"detail":{"lastStatus":"STOPPED","stopCode":"SpotInterruption"}}
{... new task RUNNING ...}
aws:ecs:RunTask) has ecs:RunTask and ecs:CreateTask permissions.{
"Version": "2012-10-17",
"Statement": [
{"Effect": "Allow", "Action": ["ecs:RunTask", "ecs:CreateTask"], "Resource": "*"}
]
}
If you are observing that the task is not restarting, confirm that the task was launched as part of a service and that the service’s desiredCount is greater than zero. If either condition is not met, the scheduler will not auto‑reschedule.
Use comments to ask for clarification. Post a solution as an answer.
35,275 reputation · 14 Feb 2023, 07:18 UTC
So, if your service’s desired count is >0 and you’re not using a CodeDeploy deployment controller, the replacement happens automatically—you just need to monitor the slight gap to avoid brief downtime.