A developer is configuring an Amazon CloudWatch Logs subscription filter to stream logs from an application to an Amazon Kinesis Data Stream. The application logs are structured JSON documents that contain a root-level key `statusCode` and a nested object `errorInfo` with a key `severity`. The developer wants the subscription filter to select only log events where `statusCode` is 500 and `severity` is 'CRITICAL'. Which filter pattern must the developer use?
- { .statusCode = 500 && .errorInfo.severity = "CRITICAL" }Answer
- B{ .errorInfo.severity == "CRITICAL" }
- Cfields statusCode, errorInfo.severity | filter statusCode = 500 and errorInfo.severity = "CRITICAL"
- D[statusCode = 500, errorInfo.severity = "CRITICAL"]
Answer
The correct filter pattern is `{ .statusCode = 500 && .errorInfo.severity = "CRITICAL" }`.
The correct pattern `{ .statusCode = 500 && .errorInfo.severity = "CRITICAL" }` properly follows the CloudWatch Logs filter pattern syntax for JSON logs. It uses curly braces, dot notation for nested JSON properties, a single `=` for comparison, and `&&` for a logical AND relationship.
Step-by-Step Solution
Key Concept
CloudWatch Logs Filter Pattern Syntax for JSON Log Events