An order processing system publishes JSON-formatted logs to Amazon CloudWatch Logs. The logs contain a top-level key named `status`. A representative log event is:
{
"orderId": "1001",
"status": "Failed",
"code": 500
}
Which filter pattern should be applied to the log group to capture these specific events?
- { $.status = "Failed" }Answer
- B$.status = "Failed"
- C[status = "Failed"]
- D{ status == "Failed" }
Answer
The correct filter pattern is `{ $.status = "Failed" }`.
The correct pattern is `{ .status = "Failed" }` because structured JSON logs in CloudWatch Logs must be queried with patterns enclosed in curly braces. Within the braces, the root object is represented by ``, followed by the key name (e.g., `$.status`), and a single equals sign `=` is used for string or numeric value comparison.
Step-by-Step Solution
Key Concept
CloudWatch Logs Metric Filter JSON Syntax