# Troubleshooting

| Symptom | Likely cause | Fix |
|---------|--------------|-----|
| `terraform apply` fails on `archive_file` | Lambda folder missing next to `terraform/` | Keep `lambda/` and `terraform/` as siblings from the zip |
| 400 missing key | Forgot `Idempotency-Key` | Header is required on every mutating call |
| 409 different body | Reused a key for a new amount | New logical checkout → new UUID |
| 409 in flight | Crash drill or slow gateway | Wait for sweeper (~1 min on AWS) or retry later with the **same** key |
| 503 | Store down | Fail closed. Do not charge. |
| Demo hits localhost and fails | `local_server.py` not running and no Terraform state | Start the local server **or** `terraform apply` first |
| Worker never writes webhook rows | SQS KMS key does not allow Lambda | Use the lab Terraform; do not swap in a generic CMK without grants |
| `orders` count > 1 after retry | You changed the key | The key is the operation. A new key is a new charge. |

CloudWatch: `/aws/lambda/{prefix}-charge`, `-worker`, `-sweeper`.
