A SysOps Administrator is configuring a monitoring solution for a new microservice that writes JSON-formatted application logs to an Amazon CloudWatch Logs group. A typical log entry has the following structure:
{
"timestamp": "2026-07-15T12:00:00Z",
"level": "ERROR",
"event": {
"service": "database-connector",
"error_code": 504,
"message": "Connection timed out after 10000ms"
}
}
The administrator wants to increment a custom CloudWatch metric whenever the `service` value is "database-connector" and the `error_code` is 504. Which configuration will achieve this requirement?
- Create a CloudWatch Logs metric filter with the filter pattern `{ .event.service = "database-connector" && .event.error_code = 504 }` and associate it with a metric transformation.Cevap
- BCreate an Amazon EventBridge rule that intercepts the CloudWatch log group events and triggers an AWS Systems Manager Automation document to parse the JSON log stream and increment the custom metric.
- CEnable detailed monitoring on the EC2 instances hosting the microservice, which automatically configures CloudWatch to parse the application logs for error events and generate the metric at 1-minute intervals.
- DConfigure a log retention policy on the CloudWatch log group to aggregate log events hourly and publish them to an Amazon S3 bucket for metric transformation.
Cevap
Create a CloudWatch Logs metric filter with the filter pattern `{ .event.service = "database-connector" && .event.error_code = 504 }` and associate it with a metric transformation.
The correct answer is the configuration that creates a CloudWatch Logs metric filter with the filter pattern `{ .event.service = "database-connector" && .event.error_code = 504 }` and associates it with a metric transformation. CloudWatch Logs natively supports parsing JSON log entries. By using dot notation (e.g., `$.event.service`), you can reference nested keys, and the single equals sign (`=`) is the standard comparison operator within JSON filter pattern syntax.
Adım Adım Çözüm
Anahtar Kavram
Filtering JSON-formatted logs using CloudWatch metric filters and dot notation