A developer is troubleshooting a serverless application where an AWS Lambda function has a configured timeout of 15 seconds. The function is designed to write a custom JSON log entry to Amazon CloudWatch Logs at the end of its execution, structured as { "requestID": "123-456", "status": "COMPLETED", "executionTimeMs": 1250 }. If a database delay occurs, the function catches it and logs { "requestID": "123-456", "status": "ERROR", "errorType": "DatabaseTimeout" }. To track performance issues and failures, the developer configures a CloudWatch Metric Filter with the pattern { (.executionTimeMs > 15000) }. During testing, several invocations time out, but the metric filter does not register any data points. Why is the metric filter failing to capture these timeout events?
- AThe metric filter pattern is invalid because CloudWatch Logs JSON filter expressions require the double equality operator '==' rather than a single '=' for string equality evaluations.
- When a Lambda function times out, the execution is abruptly terminated by the Lambda runtime, preventing the custom log statement from being written. The metric filter must instead match the platform-generated log string 'Task timed out'.Answer
- CLambda execution environments run in isolated sandboxes that prevent CloudWatch metric filters from reading log streams until the sandbox is completely recycled.
- DThe metric filter is failing because JSON property names containing mixed case characters, such as 'executionTimeMs', must be converted to uppercase within the filter pattern expression.