A developer is monitoring a serverless application where the Lambda functions write structured JSON log events to Amazon CloudWatch Logs. A sample log event is shown below:
{
"request_id": "req-98765",
"status": "Failure",
"http_status": 504
}
The developer attempts to create a CloudWatch Metric Filter to count the occurrences of gateway timeouts where the request has a status of "Failure" and an http_status of 504. The developer configures the following filter pattern:
`{ .status == "Failure" && .http_status == 504 }`
After applying this filter, the metric is not populated even though log events matching these criteria are present in the log group. Which of the following explains why the metric filter is failing to match the log events?
- The metric filter pattern uses double equal signs for comparison, which is invalid syntax; the pattern must use a single equal sign for equality comparison.Cevap
- BThe filter pattern must use space-delimited syntax enclosed in square brackets because CloudWatch Logs does not natively parse JSON log structures.
- CThe double ampersand operator is not supported in CloudWatch metric filters; logical operations must be split into separate, single-condition metric filters.
- DThe Lambda function's IAM execution role lacks permissions to publish to the metric filter, preventing the filter from being evaluated as logs are written.
Cevap
The metric filter pattern uses double equal signs for comparison, which is invalid syntax; the pattern must use a single equal sign for equality comparison.
The correct option is correct because Amazon CloudWatch Logs JSON metric filters utilize a single equal sign (=) for matching field values. The use of a double equal sign (==) is unsupported and results in the filter failing to match the JSON log events, leaving the metric unpopulated.
Adım Adım Çözüm
Anahtar Kavram
CloudWatch Logs Metric Filter JSON Syntax and Operators
Tahmini Süre:1m 30s