Skip to main content

Alarms

Alarms are defined in infra/lib/observability-stack.ts (one set per stage) and infra/lib/billing-stack.ts (prod only). Each stage's alarms publish to an SNS topic, caregiver-{stage}-alarms. Each topic has one confirmed email subscription. The subscription was added by hand, not in CDK, so it would have to be re-added if a topic were ever recreated.

An alarm emails once, when it enters ALARM. Nothing is sent when it returns to OK, so check the CloudWatch console to see whether it has cleared.

caregiver-{stage}-api-errors​

  • Fires when the API Lambda reports more than 5 errors in 5 minutes.
  • Means: the Lambda crashed or timed out, not just that a handler answered 500. A handler's 500 is a normal response as far as Lambda is concerned. Usual causes are a panic, a missing environment variable at startup, or the 10-second timeout.
  • Check first:
    1. the "errors in the last hour" and "panics" queries in Logs;
    2. whether a deploy just finished (the cd-main run);
    3. the dashboard's invocations graph, for a traffic spike.

caregiver-{stage}-api-p95-latency​

  • Fires when the API's 95th-percentile duration is over 2 seconds for two 5-minute periods in a row.
  • Means: requests are slow, usually from DynamoDB (a scan or a large query) or a cold start under load.
  • Check first:
    1. the "slowest routes" query in Logs, to see which route;
    2. X-Ray traces for that route (tracing is on for both Lambdas), to see which DynamoDB call takes the time.

caregiver-{stage}-api-throttles​

  • Fires when the API Lambda is throttled at least once in 5 minutes.
  • Means: more requests at once than Lambda allows the function. At this app's traffic that points to a loop: an app bug retrying, or a script.
  • Check first:
    1. the dashboard's invocations graph;
    2. the "requests per caller" query in Logs, to find who is calling.

caregiver-{stage}-generator-errors​

  • Fires when the daily generator run fails once.
  • Means: at least one schedule or coverage schedule was not topped up, or the run could not start. Scheduled entries still exist for the next few days, because each run writes 14 days ahead, so this is not urgent within the day.
  • Check first:
    1. the "generator failures" query in Logs: each failure names its schedule_id or coverage_schedule_id;
    2. the "run complete" line, for counts of failed against written.
  • To rerun once fixed: aws lambda invoke --function-name caregiver-prod-generator out.json. Rerunning is safe, because it never writes an entry twice.

caregiver-cloudwatch-billing-tripwire (prod, us-east-1)​

  • Fires when the account's estimated month-to-date charges pass $5.
  • Caution: this alarm has no action, so it notifies no one. It only shows as ALARM in the CloudWatch console. Also, despite its name, it watches total estimated charges, not only CloudWatch's.

caregiver-monthly-overall (AWS Budgets)​

  • An AWS budget, not a CloudWatch alarm. It emails the prod alert address (CAREGIVER_ALERT_EMAIL) when actual spend passes 80% of $20 in a month.

Testing the email path​

aws cloudwatch set-alarm-state --alarm-name caregiver-dev-api-errors \
--state-value ALARM --state-reason "testing the alarm email"
# then put it back
aws cloudwatch set-alarm-state --alarm-name caregiver-dev-api-errors --state-value OK --state-reason "done"