All case studies

Containers

4,222 failed tasks on a first deploy to a new region

A service crash-looped on its first deploy to Sydney. Memory and network were fine. The real cause was a 403 during startup, because two services disagreed about which tenant they belonged to.

Stack
Amazon ECS, Application Load Balancer health checks, NestJS, AWS Secrets Manager
My role
Root cause and the fix
Outcome
The service was stable right after the fix. A second service with the same problem was fixed in minutes.

What people saw

Tasks were exiting with code 137 after failing load balancer health checks, thousands of times over. Exit 137 means the process was killed with SIGKILL. That often points to the out-of-memory killer, but memory was at 8%. Here, ECS was stopping tasks the load balancer had marked unhealthy: it sends SIGTERM, waits for the stop timeout, then sends SIGKILL to anything still running.

Why the port never opened

The container logs showed the app never finished starting. During startup, the service fetched tenant configuration from the platform’s internal API, and that call returned 403 “Incorrect API key”. Startup waited on that call and never got past it, so the app never opened its port. The health check failed, ECS replaced the task, and the cycle repeated.

Two services, two answers to the same question

Both services choose their internal API key the same way. First they work out an org ID: from an environment variable if it’s set, otherwise from a map keyed by environment prefix. Then they fetch that org’s current key from Secrets Manager.

Other regions only worked because both services’ maps happened to include their prefix.

The fix

One environment variable on the task definition, so the service resolved the correct org. It recovered immediately. The next day, a second service hit the same problem. It used a different variable name for the same input, and because the pattern was already written down, it was fixed in minutes.

Follow-ups I proposed

What I’d do differently

What I took from it

  • Exit 137 is a symptom. Read the task’s stop reason before assuming it ran out of memory.
  • A hard dependency during startup turns a config mistake into a crash loop.
  • “It works in every other region” can be luck. Check whether the other regions have the same config, or just happen to work.