An application running on AWS Fargate writes structured JSON logs to an Amazon CloudWatch Logs log group. A developer needs to track the frequency of database connection errors. A sample log event is shown below:
{
"timestamp": "2026-07-14T12:00:00Z",
"event_type": "database_connect",
"status": "error",
"latency_ms": 2500
}
Which actions must the developer take to configure the metric filter correctly? (Select TWO.)
- Define the metric filter pattern as `{ (.event_type = "database_connect") && (.status = "error") }`Answer
- Set the metric value of the metric transformation to `1`Answer
- CDefine the metric filter pattern as `[timestamp, event_type="database_connect", status="error", latency_ms]`
- DSet the metric value of the metric transformation to `$.latency_ms`
- EDefine the metric filter pattern using the query syntax `fields @timestamp, event_type | filter event_type = "database_connect" and status = "error"`
Answer
Define the metric filter pattern as `{ (.event_type = "database_connect") && (.status = "error") }` and set the metric value of the metric transformation to 1.
To create a metric filter for structured JSON logs, the pattern must follow CloudWatch's JSON syntax which utilizes curly braces `{}` and dot notation (`$.property`) to reference nested keys. The logical operator `&&` is used to join the two conditions. Additionally, since the goal is to count the frequency of occurrences of these errors, the metric value must be set to `1` so that the custom metric increments by 1 for every match.
Step-by-Step Solution
Key Concept
Creating CloudWatch metric filters for JSON logs to track frequency of events