A developer is configuring a CloudWatch Metric Filter to count the occurrences of HTTP 5xx errors from a web application's JSON-formatted log group. The JSON log events have the structure: `{"statusCode": 500, "message": "Internal Server Error"}`. The metric filter must count all events where `statusCode` is greater than or equal to 500. Which of the following configurations are required to correctly achieve this? (Select TWO.)
- Define the metric filter pattern as `{ $.statusCode >= 500 }` to match the JSON key-value pair.Answer
- Set the metric value in the filter configuration to 1 to increment the metric count by 1 for each matching log event.Answer
- CDefine the metric filter pattern as `[statusCode >= 500]` using space-delimited syntax.
- DIncrease the execution timeout of the application's AWS Lambda function to allow CloudWatch Logs more time to process the metric filter.
- EConfigure an IAM Trust Policy on the log group to allow it to assume the role required to run the metric filter.
Answer
Define the metric filter pattern as `{ $.statusCode >= 500 }` and set the metric value in the filter configuration to 1.
The correct options are the ones stating to define the metric filter pattern as `{ .statusCode >= 500 }` and to set the metric value in the filter configuration to 1. CloudWatch Logs supports filtering JSON log messages using curly braces `{}` and the `.property` notation to inspect properties of the JSON object. Specifying a metric value of 1 instructs CloudWatch to increment the metric by 1 for each matching log event.
Step-by-Step Solution
Key Concept
CloudWatch Logs Metric Filters syntax and configuration for JSON-formatted log events.
Estimated Time:1m 0s