Question

Difficulty: HardMonitoring and Analyzing Logs with Amazon CloudWatch

A developer is configuring a custom Amazon CloudWatch metric filter to monitor performance metrics from an API gateway service. The service writes structured JSON logs to a CloudWatch log group. A representative log event has the following structure:

{
"service": "payment-api",
"transaction": {
"success": true,
"amount": 250.00
},
"latency": 150
}

The developer needs to create a metric filter that publishes to a custom metric named `HighValueLatency` in the `PaymentMetrics` namespace. The metric must record the `latency` value, but only for events where the transaction `success` is `true` and the transaction `amount` is strictly greater than 200200.

Which TWO configurations or values must the developer specify in the metric filter settings to achieve this?

  1. Set the filter pattern to `{ (.transaction.success = true) && (.transaction.amount > 200) }`Answer
  2. Set the metric value to `$.latency`Answer
  3. C
    Set the filter pattern to `{ .transaction.success == true && .transaction.amount > 200 }`
  4. D
    Set the metric value to `$latency`
  5. E
    Set the filter pattern to `filter transaction.success = true and transaction.amount > 200`

Answer

Set the filter pattern to `{ (.transaction.success = true) && (.transaction.amount > 200) }` and set the metric value to `$.latency`
To extract a specific field value from a JSON log event based on multiple conditions, the developer must specify both a valid filter pattern and a valid metric value. The pattern must enclose each individual comparison within parentheses and join them with the `&&` operator, using a single `=` for equality, which matches `{ (.transaction.success = true) && (.transaction.amount > 200) }`. The metric value must refer to the desired JSON path using standard dot notation starting with `.,whichmatches.`, which matches `.latency`.

Step-by-Step Solution

1
Formulate the JSON path expressions for the target fields.
The target fields are transaction success, transaction amount, and latency. The corresponding JSON path expressions are `.transaction.success,.transaction.success`, `.transaction.amount`, and `$.latency`.
CloudWatch Logs metric filters use JSON path notation starting with `$.` to reference properties in a JSON log event.
2
Construct the multi-conditional filter pattern.
Combine the conditions using the syntax `{ (condition1) && (condition2) }`, which yields `{ (.transaction.success = true) && (.transaction.amount > 200) }`.
When evaluating multiple conditions in a JSON metric filter, each comparison must be enclosed in parentheses and joined by logical operators like `&&`.
3
Define the metric value extractor.
Specify `$.latency` as the metric value in the metric filter configuration.
To record the actual latency value rather than a count of events, the metric value must point to the specific JSON path containing the numeric measurement.

Key Concept

CloudWatch Metric Filter JSON parsing and pattern syntax
Estimated Time:2m 30s
Rate this question