# Roll back one ECS service to its previous revision
Services: any · Owner: DevOps

## Symptom
A deploy (from `b2g-cd` / `b2g-cd-demo`) made a service worse: new 5xx, failing health checks, broken
page.

## Confirm it is this
The errors started at the deploy time. Check CodeBuild `b2g-cd` (prod) or `b2g-cd-demo` (demo), and
the service's **Deployments** tab in the ECS console.

## Fix: roll back
Every image is tagged with its commit sha, and every deploy registers a new task-definition revision,
so a rollback is pointing the service at the previous revision. PowerShell or bash:

```bash
# prod: cluster b2g-prod, family b2g-<svc>; demo: cluster b2g-demo, family b2g-demo-<svc>
aws ecs list-task-definitions --family-prefix b2g-<svc> --sort DESC --max-items 5 --region ap-south-1
aws ecs update-service --cluster b2g-prod --service <svc> --task-definition b2g-<svc>:<previous-revision> --region ap-south-1
aws ecs wait services-stable --cluster b2g-prod --services <svc> --region ap-south-1
```

Out-of-band config (env vars, secrets, CPU/memory) lives on the task definition, so the previous
revision brings its own config back with it.

## Then make it stick
CD is self-healing: the next `b2g-cd` run compares the running sha with `main` and **redeploys the
bad commit** unless `main` changes. Revert the merge on `main` through a PR (or on `prelive` for
demo) before the next build. See `CI-CD-PROCESS.md`.

## Prevent
Add the failure mode as its own runbook and an eval case.
