Skip to main content

Logs

Both Lambdas write JSON logs to CloudWatch Logs in us-east-2. Prod keeps them for 30 days and dev for 7.

FunctionLog group
API/aws/lambda/caregiver-{stage}-api
Generator/aws/lambda/caregiver-{stage}-generator

Follow the live log from a terminal:

aws logs tail /aws/lambda/caregiver-prod-api --follow --format short

What is in a line​

Every line carries service and env. The API adds per-request fields (logging middleware):

FieldMeaning
request_idAPI Gateway's request ID. Every line from one request shares it.
method, pathThe request as sent, for example GET /v1/trackers/t-123.
user_idThe caller's Cognito sub, once authentication has run.
routeThe matched pattern, for example GET /v1/trackers/{trackerId}. On the final line only.
status, duration_ms, bytesThe response. On the final line only.
err, client_msgOn "server error" lines: the real error, and what the app was told.

Each request ends with exactly one line whose msg is "request".

msgLevelMeans
requestINFOOne per request: status and timing.
server errorERRORA handler answered 500; err says why.
panicERRORA handler crashed; stack has the stack trace.
email sync failedWARNCopying a changed email onto the user failed; it retries on the next request.
schedule generation failed; the daily job will fill it inERRORSaving a schedule worked, but writing its entries didn't. The next generator run will fill them in.
run completeINFOGenerator: the day's counts.
schedule failed, coverage schedule failedERRORGenerator: one schedule failed, with its IDs.

Queries​

Run these in CloudWatch → Logs Insights, choosing the log group and a time range.

Errors in the last hour (API):

fields @timestamp, msg, route, status, err, client_msg, request_id
| filter level = "ERROR"
| sort @timestamp desc
| limit 50

Everything for one request, given a request_id from an error line:

fields @timestamp, level, msg, err
| filter request_id = "PASTE-ID"
| sort @timestamp asc

Slowest routes:

filter msg = "request"
| stats count(*) as calls, pct(duration_ms, 95) as p95_ms, max(duration_ms) as max_ms by route
| sort p95_ms desc

5xx by route:

filter msg = "request" and status >= 500
| stats count(*) as errors by route, status
| sort errors desc

Requests per caller (for a loop or a flood):

filter msg = "request"
| stats count(*) as calls by user_id
| sort calls desc
| limit 20

Panics:

fields @timestamp, path, recover, stack
| filter msg = "panic"
| sort @timestamp desc

Generator failures (generator log group):

fields @timestamp, msg, schedule_id, coverage_schedule_id, receiver_id, team_id, err
| filter level = "ERROR" or msg = "run complete"
| sort @timestamp desc

Traces​

X-Ray tracing is on for both Lambdas. In CloudWatch → X-Ray traces, filter by URL or by response time to see how long each DynamoDB call in a slow request took.