epok
View as Markdown

AWS Lambda logs and metrics

Updated Nov 22, 2026 · today

Lambda writes every stdout/stderr line to a CloudWatch Logs group, and publishes its metrics under the AWS/Lambda namespace. Both reach Epok through the shared setup on AWS: logs and metrics. Nothing runs inside the function.

On this page: What you getTurn on logsMetricsUseful searchesTroubleshooting

What you get

  • Logs: every line your function writes to standard output or standard error, from the group /aws/lambda/<function-name>.
  • Metrics: the AWS/Lambda namespace, which includes invocations, errors, duration, throttles and iterator age.

Each log event is stored with _msg (the line), _time, a level detected from the first of FATAL or CRITICAL, ERROR, WARN, DEBUG or TRACE found as a word (else info), service (the last part of the log group name), log_group, log_stream, cloud.provider, cloud.account_id and cloud.region.

Turn on logs

  1. Lambda turns this on by itself: the first invocation creates the log group, provided the function's execution role has logs:CreateLogGroup, logs:CreateLogStream and logs:PutLogEvents. The managed AWSLambdaBasicExecutionRole policy includes all three.
  2. Find the group name with aws lambda get-function --function-name <name> --query 'Configuration.LoggingConfig' or in the Lambda console under Monitor, then View logs in CloudWatch.
  3. Add the group to EPOK_LOG_GROUPS and run the setup on AWS: logs and metrics.

Metrics

The namespace is AWS/Lambda. It is in the default metric stream list, so it arrives with the normal metrics setup and no extra input.

text
log_group:"/aws/lambda/checkout" level:error   # errors from one function
service:checkout _msg:"Task timed out"        # a specific failure, any log group
level:error _time:1h | stats by (service) count()  # which functions error the most
_msg:err*                                      # prefix match across the message

Troubleshooting

  1. No log group exists. The function has never run, or its execution role lacks the three logs: permissions above. Invoke it once and re-check.
  2. The level looks wrong. Level is read from the first word in the line that matches FATAL or CRITICAL, ERROR, WARN, DEBUG or TRACE (any case), not from a JSON field. A line that has none of these words is stored as info. Search the message text with _msg: when the level does not help.
  3. Metrics missing. The metric stream can take 3 to 15 minutes after creation, and the metrics stack is separate from the logs stack. Run bash aws-metrics.sh --verify-only.

Next