Question

Difficulty: HardMonitoring and Analyzing Logs with Amazon CloudWatch

A developer has a payment-processing application implemented as an AWS Lambda function. During peak hours, this function occasionally fails because it exceeds its configured timeout limit of 15 seconds. The developer needs to configure an Amazon CloudWatch Logs metric filter to count these timeout occurrences and trigger an alarm. The log group contains both application-generated JSON logs and standard Lambda platform logs. The Lambda platform writes the timeout log as a plain text string:

`2026-07-14T17:20:32.123Z 88a381cf-192a-4a6f-9988-51fcf5498bd6 Task timed out after 15.02 seconds`

Which of the following is the correct configuration or filter pattern for this metric filter?

  1. A
    Set the filter pattern to { $.message = "Task timed out*" } to extract the message field from the platform log.
  2. Set the filter pattern to "Task timed out" to match the plain text log line generated by the Lambda service.Answer
  3. C
    Catch the timeout exception within the Lambda function code using a try-catch block, write a custom JSON log with a status of "timeout", and set the filter pattern to { $.status = "timeout" }.
  4. D
    Set the filter pattern to [timestamp, request_id, message = "*Task timed out*"] to parse the space-delimited log line.

Answer

Set the filter pattern to "Task timed out" to match the plain text log line generated by the Lambda service.
The correct answer is to use a simple text/phrase filter pattern. The Lambda platform writes timeout logs as plain text rather than JSON. An exact phrase match in double quotes like "Task timed out" will correctly scan the log group and match these events.

Step-by-Step Solution

1
Analyze the log format of the target event
The target event is a standard Lambda platform timeout log, which is a plain text string: `2026-07-14T17:20:32.123Z 88a381cf-192a-4a6f-9988-51fcf5498bd6 Task timed out after 15.02 seconds`.
Understanding the format (JSON vs. plain text) is critical to selecting the correct CloudWatch Logs filter pattern type.
2
Determine if application-level handling is possible
Since execution timeouts are enforced by the Lambda service, the execution context is immediately halted. Application code cannot catch the timeout to write a custom JSON log.
This rules out relying on custom JSON logs for timeout monitoring.
3
Select the correct filter pattern syntax for plain text logs
Since the log is plain text, JSON filter syntax cannot be used. A simple phrase match pattern like "Task timed out" must be used to match the exact substring.
Using double quotes ensures an exact, case-sensitive phrase match for the plain text log line.

Key Concept

Monitoring and Analyzing Logs with Amazon CloudWatch
Estimated Time:2m 0s
Rate this question