A developer is troubleshooting an AWS Lambda function with a configured timeout of 10 seconds. The function is occasionally failing to process incoming payloads. The developer wants to configure an Amazon CloudWatch Logs metric filter to count how many times the function executions are terminated due to timeouts, and to trigger an alarm. The application code is designed to log custom execution details in JSON format, including `{ "execution_time_ms": 10500, "status": "success" }`, at the end of the handler execution. Which configuration should the developer implement to reliably monitor these execution timeouts?
- ACreate a metric filter on the log group with the pattern `{ $.execution_time_ms > 10000 }` and create a CloudWatch alarm based on this metric.
- BCreate a metric filter on the log group with the pattern `{ $.status = "timeout" }` and create a CloudWatch alarm based on this metric.
- Create a metric filter on the log group with the pattern "Task timed out" and create a CloudWatch alarm based on this metric.Answer
- DCreate a metric filter on the log group with the pattern `[timestamp, request_id, status = "timeout"]` and create a CloudWatch alarm based on this metric.
Answer
Create a metric filter on the log group with the pattern "Task timed out" and create a CloudWatch alarm based on this metric.
When a Lambda function times out, the Lambda service halts execution immediately. This prevents the custom application code from completing and writing any custom JSON log events. Instead, the service writes a message containing 'Task timed out' to the log stream. Therefore, a metric filter targeting this literal string is the only reliable way to count timeouts.
Step-by-Step Solution
Key Concept
AWS Lambda platform logging on execution timeouts vs application-level logs, and correct CloudWatch metric filter string matching.
Estimated Time:1m 30s