Question

Difficulty: EasyMonitoring and Analyzing Logs with Amazon CloudWatch

A developer is troubleshooting an application where messages are being processed multiple times from an Amazon SQS queue. The developer suspects that the consumer AWS Lambda function is timing out during execution, causing messages to return to the queue. The developer wants to monitor and analyze these timeouts using Amazon CloudWatch Logs.

Which of the following actions should the developer take to correctly identify and track these execution timeouts? (Select TWO.)

  1. Create a CloudWatch metric filter on the Lambda function's log group using the filter pattern "\"Task timed out\"" to increment a custom metric.Answer
  2. Use Amazon CloudWatch Logs Insights to run a query with the command "filter @message like /Task timed out/" on the Lambda function's log group.Answer
  3. C
    Create a CloudWatch metric filter on the log group using the filter pattern "Task timed out" (without double quotes) to count the occurrences of the timeout message.
  4. D
    Implement a try-catch block within the Lambda function handler to catch the execution timeout and write a custom log entry to CloudWatch Logs.
  5. E
    Configure a CloudWatch metric filter using the JSON pattern "{ $.errorMessage = \"Task timed out*\" }" to extract the error details.

Answer

Create a CloudWatch metric filter with the quoted pattern "Task timed out" to count occurrences of timeouts, and use CloudWatch Logs Insights to query the log group with a filter mapping the timeout phrase.
The correct options involve creating a CloudWatch metric filter using the exact phrase search pattern enclosed in double quotes (which allows tracking the exact phrase written by the Lambda service), and using CloudWatch Logs Insights with a string match filter to query these plain text timeout logs.

Step-by-Step Solution

1
Understand how AWS Lambda reports execution timeouts in CloudWatch Logs.
Identify that the Lambda service appends a plain text log line containing 'Task timed out after X seconds' when a function times out.
Since the function is abruptly terminated, the application itself cannot catch the timeout, making CloudWatch Logs analysis the only direct way to verify timeouts.
2
Select the correct pattern matching syntax for CloudWatch metric filters.
Use double quotes around the phrase "Task timed out" to perform an exact match query on the plain text log events.
Unquoted terms act as an OR condition (Task OR timed OR out), which will match other log lines and trigger false alarms.
3
Use CloudWatch Logs Insights to query historical logs.
Write a query utilizing the 'like' operator to search log streams for the timeout message.
Logs Insights allows rapid searching and analysis of log events without having to manually read through individual log streams.

Key Concept

Monitoring plain text Lambda runtime logs in CloudWatch using exact phrase metric filters and Logs Insights queries.
Rate this question