Skip to main content
Welcome back. In this walkthrough we recreate a failing ECS rolling update and analyze what went wrong. We’ll:
  • Rebuild the Docker image and push a new task definition revision from CodeBuild.
  • Deploy the new task definition revision to an ECS service and observe the failed rolling update.
  • Manually roll back to the previously working revision and explain why ECS did not automatically restore the service.
This guide preserves the exact commands and configuration used in the reproduction, while clarifying the sequence and root causes so you can apply the same troubleshooting steps in your environment.

1) Build pipeline: CodeBuild buildspec

Below is the buildspec used in CodeBuild to build, tag, and push the Docker image. Note that the tagging was corrected so both latest and the commit-hash tag are pushed.
Tips:
  • Prefer using immutable tags (commit hash or image digest) in the task definition to avoid ambiguity during rollbacks.
  • Pushing both latest and a commit-tag helps during development, but relying on latest for production rollbacks can cause recovered revisions to pull the same broken image.

2) Application change that caused the failure

We intentionally introduced a code change that caused the container to fail at runtime. The fixed snippet below shows the application after adding app and handling error in the login route while keeping the commented-out route and the commented blocks that originally introduced the issue.
This is the exact runtime state that CodeBuild packaged and pushed.

3) Git commands used to prepare the image

Commands executed to amend a commit and push a new change (output examples included):
Then a new commit and push:

4) Task definition registration

When CodeBuild completed, it updated the task-definition.json and registered a new task definition revision. The relevant portion of the registered task-definition (revision 6) is shown below:
The build pipeline substituted the commit hash into the task-definition.json, so the task definition revision is correlated with the image tag.

5) Deploying the new revision in ECS

From the ECS console we updated the service to use revision 6. On the Update Service page we selected revision 6 and clicked Update.
The image shows a webpage interface of the Amazon Elastic Container Service (ECS) with various optional service configurations like Service Connect, Service Discovery, Load Balancing, and more. There are buttons for actions like "Cancel" and "Update" at the bottom.
What happened after the update:
  • ECS started tasks for revision 6, but they failed to reach a RUNNING state.
  • The deployment hung in a loop: tasks were repeatedly started and stopped due to container start errors caused by the introduced change.
  • ECS kept trying to bring up the failing revision instead of returning to the previously working revision.

6) Manual rollback performed

To recover we manually reverted the service back to the last-known working revision:
  1. Open the service in the ECS console and click Update service.
  2. Select the previous working task definition revision (revision 5).
  3. Click Update.
After that:
  • ECS started tasks using revision 5 and the corresponding image.
  • The new failing deployment was drained and the service returned to a healthy RUNNING state.

Why ECS did not automatically roll back

Automatic rollback in ECS is not guaranteed by default. Two common blockers are:
  1. No automatic detection and abort: ECS will continue attempting a deployment until it either succeeds or you enable the deployment circuit breaker or external automation to stop it.
  2. Non-immutable image tags: If both the old and new task definitions reference a moving tag like latest, rolling back the task definition may still pull the same broken image.
Best practices: use immutable image tags (commit-hash or image digest like repo@sha256:...) and enable the ECS deployment circuit breaker or monitoring automation to detect and recover from faulty deployments.

Quick reference: Common causes and mitigation

Note: In the table cell above latest is shown as inline code to avoid parsing/ambiguity.
  • Reproduced a failing rolling update by pushing a new task definition revision with a runtime error.
  • ECS attempted the rolling update, but the deployment repeatedly failed and did not auto-rollback.
  • Manual rollback to the previous task definition revision restored the service.
  • Root cause: mutable image tags (latest) and lack of an automatic deployment abort mechanism.
Recommended actions:
  • Use immutable image tags (commit-hash tags or digests) in task definitions.
  • Enable the ECS deployment circuit breaker to automatically stop unhealthy deployments:
  • Implement health checks (load balancer and container-level) and CloudWatch alarms to detect failed deployments quickly.
  • Ensure CI/CD injects the immutable image identifier into the task definition that you register.
Further reading and references: That’s all for now—apply immutable tagging and circuit-breaker protections to avoid similar deadlock-style failures in rolling updates.

Watch Video