Question

Difficulty: MediumMonitoring and Analyzing Logs with Amazon CloudWatch

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?

  1. A
    Create a metric filter on the log group with the pattern `{ $.execution_time_ms > 10000 }` and create a CloudWatch alarm based on this metric.
  2. B
    Create a metric filter on the log group with the pattern `{ $.status = "timeout" }` and create a CloudWatch alarm based on this metric.
  3. Create a metric filter on the log group with the pattern "Task timed out" and create a CloudWatch alarm based on this metric.Answer
  4. D
    Create 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

1
Analyze Lambda execution behavior during a timeout
When a Lambda function reaches its configured timeout limit (10 seconds in this scenario), the AWS Lambda service terminates the execution container immediately.
This shows that any application-level code designed to run at the end of the handler (such as writing a custom JSON log with execution metrics) is never executed.
2
Identify the log event recorded during a timeout
The AWS Lambda service runtime writes a platform-generated log line to the log stream, containing the phrase: 'Task timed out after 10.00 seconds'.
To reliably track timeouts, the metric filter must search for this platform-generated text rather than custom JSON properties that are only written upon successful handler execution.
3
Select the correct CloudWatch Logs Metric Filter syntax
The literal pattern "Task timed out" is used to match the platform log event. An alarm is then associated with this metric to trigger notifications or scaling actions.
This correctly targets the service-level error message and tracks execution failures accurately.

Key Concept

AWS Lambda platform logging on execution timeouts vs application-level logs, and correct CloudWatch metric filter string matching.
Estimated Time:1m 30s
Rate this question