Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

GitHub Actions hangs on the Amazon ECS deploy step until it times out

Your error

The amazon-ecs-deploy-task-definition step keeps running for wait-for-minutes (30 by default) and then fails3 more lines it can show

Fix it fast

Most common cause, 1 of 3

The new tasks start and then stop, again and again

Fix what stoppedReason reports (an image tag that does not exist, a crash on start, a health check path that fails), then push again.

Fix
aws ecs update-service --cluster my-cluster --service my-service \
  --deployment-configuration "deploymentCircuitBreaker={enable=true,rollback=true},maximumPercent=200,minimumHealthyPercent=100"
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

With wait-for-service-stability set to true, aws-actions/amazon-ecs-deploy-task-definition@v2 polls until the ECS service has exactly one deployment and runningCount equals desiredCount, for 30 minutes by default. It hangs when the new tasks keep stopping, cannot be placed, or the deployment settings block the swap. The service events name which one; fix it and turn on the circuit breaker.

  • Applies to aws-actions/amazon-ecs-deploy-task-definition v2.6.4, Amazon ECS rolling update (ECS deployment controller), AWS CLI 2.42
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

While the workflow step is still waiting, ask ECS what the service is doing. Two deployments that never shrink to one, plus the newest event messages, tell the three causes apart.

Run this first
aws ecs describe-services --cluster my-cluster --services my-service \
  --query 'services[0].{deployments: deployments[].[status,rolloutState,runningCount,desiredCount], events: events[:5].message}'

Then find the line you see in this list and open its fix:

  1. 1The new tasks start and then stop, again and againStopped tasks pile up for the new task definition revision, and the events say the service is unable to consistently start tasks successfully
  2. 2ECS cannot find room for the new tasksThe events say the service was unable to place a task because no container instance met all of its requirements
  3. 3minimumHealthyPercent and maximumPercent leave no room to swap tasksThe events say the service was unable to stop or start tasks during a deployment because of the service deployment configuration

What does the error look like?

  • The amazon-ecs-deploy-task-definition step keeps running for wait-for-minutes (30 by default) and then fails
  • was unable to place a task because no container instance met all of its requirements.
  • is unable to consistently start tasks successfully.
  • was unable to stop or start tasks during a deployment because of the service deployment configuration.

Cause 1 of 3

The new tasks start and then stop, again and again

You seeStopped tasks pile up for the new task definition revision, and the events say the service is unable to consistently start tasks successfully

Check

The deploy step waits out its whole timer when the tasks of the new revision crash, fail their container or load balancer health check, or cannot pull their image. The action's waiter only returns once a single deployment is left with all desired tasks running, and without the deployment circuit breaker ECS keeps retrying the bad revision, with longer gaps between attempts. Read why the last tasks stopped.

Check
aws ecs list-tasks --cluster my-cluster --service-name my-service \
  --desired-status STOPPED --query 'taskArns[:3]'
aws ecs describe-tasks --cluster my-cluster --tasks <task-arn> \
  --query 'tasks[].[stoppedReason,containers[].reason]'

Fix

Fix what stoppedReason reports (an image tag that does not exist, a crash on start, a health check path that fails), then push again. Turn on the circuit breaker with rollback as well: a revision that keeps failing then moves to FAILED and rolls back, and the current v2 action reports the rollback and fails the job instead of sitting there until the timeout.

Fix
aws ecs update-service --cluster my-cluster --service my-service \
  --deployment-configuration "deploymentCircuitBreaker={enable=true,rollback=true},maximumPercent=200,minimumHealthyPercent=100"

Verify

The next run finishes the deploy step, and the service shows one deployment whose rolloutState is COMPLETED.

Verify
aws ecs describe-services --cluster my-cluster --services my-service --query 'services[0].deployments[].[status,rolloutState,runningCount,desiredCount]'

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 2 of 3

ECS cannot find room for the new tasks

You seeThe events say the service was unable to place a task because no container instance met all of its requirements

Check

On the EC2 launch type, the step hangs when no container instance has enough free CPU, memory or network interfaces, or when the task uses a fixed host port that the old task still holds. When the minimum healthy percent is 100, the old task stays up until the new one runs, so on a single instance a fixed port can never be freed. The rest of the event message names the missing resource.

Check
aws ecs describe-services --cluster my-cluster --services my-service \
  --query 'services[0].events[?contains(message, `unable to place`)].message | [:3]'

Fix

Add container instances or a capacity provider that scales them, or lower the task's CPU and memory. For a fixed host port, AWS suggests dynamic host port mapping; if a short outage is acceptable, a minimum healthy percent of 0 lets ECS stop the old task first.

Fix
# Only when brief downtime is acceptable: stop the old task before the new one starts
aws ecs update-service --cluster my-cluster --service my-service \
  --deployment-configuration "maximumPercent=100,minimumHealthyPercent=0"

Verify

A new task reaches RUNNING and the events end with has reached a steady state.

Verify
aws ecs describe-services --cluster my-cluster --services my-service --query 'services[0].events[:2].message'

Confirmed by docs.aws.amazon.com

Did this fix it?

Cause 3 of 3

minimumHealthyPercent and maximumPercent leave no room to swap tasks

You seeThe events say the service was unable to stop or start tasks during a deployment because of the service deployment configuration

Check

A rollout is blocked when the deployment configuration lets the scheduler neither stop an old task nor start an extra one. ECS rounds the minimum healthy percent up and the maximum percent down against the desired count, so a maximum of 125 percent of three tasks still means three, and a minimum of 100 percent keeps every old task. The rollout never moves and the action waits out its timer.

Check
aws ecs describe-services --cluster my-cluster --services my-service --query 'services[0].[desiredCount,deploymentConfiguration]'

Fix

Choose values that let ECS start or stop at least one task, as AWS requires. A maximum of 200 with a minimum of 100 lets ECS start a full set of new tasks before it stops any old ones.

Fix
aws ecs update-service --cluster my-cluster --service my-service \
  --deployment-configuration "maximumPercent=200,minimumHealthyPercent=100"

Verify

describe-services soon lists a single PRIMARY deployment with runningCount equal to desiredCount.

Verify
aws ecs describe-services --cluster my-cluster --services my-service --query 'services[0].deployments[].[status,runningCount,desiredCount]'

Confirmed by docs.aws.amazon.com

Did this fix it?

How do I stop it coming back?

  • Keep the action on the floating @v2 tag (v2.6.4 now), which checks the deployment after the wait, so a circuit-breaker rollback fails the job instead of passing it.
  • Set wait-for-minutes to a little more than your slowest healthy deploy, not the full 30, so a stuck rollout fails fast.
  • Turn on the deployment circuit breaker with rollback on every service the workflow deploys, and alarm on the SERVICE_DEPLOYMENT_FAILED event in EventBridge.
  • Run the new image once with the same task definition in a test service before the production deploy, so a crash on start shows up there.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Dispatch Pro, Raheeb, Loade Driver.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.