A SysOps Administrator is configuring a monitoring solution for a microservices-based application running on Amazon EC2. The application logs are sent to Amazon CloudWatch Logs. The application outputs space-delimited log entries in the following format:
`2026-07-14T12:00:00Z WARN PaymentService 503 150`
The administrator needs to create a metric filter to monitor the frequency of HTTP 503 Service Unavailable errors generated by the PaymentService specifically, and trigger an Amazon SNS notification when this happens. What is the correct way to configure this monitoring and alerting setup?
- Create a CloudWatch metric filter with the pattern `[timestamp, log_level, service_name = PaymentService, status_code = 503, execution_time]`. Configure a CloudWatch alarm based on this custom metric, and set the alarm action to send a notification to the Amazon SNS topic.Answer
- BEnable detailed monitoring on the EC2 instances. Create a CloudWatch metric filter with the pattern `[timestamp, log_level, service_name = PaymentService, status_code = 503, execution_time]` to ensure that the custom metric is evaluated and published at 1-minute intervals.
- CCreate a CloudWatch metric filter using the JSON pattern `{ .service_name = "PaymentService" && .status_code = 503 }`. Configure a CloudWatch alarm on the log group retention settings to notify the SNS topic when the retention period is reached.
- DCreate an Amazon EventBridge rule that directly parses the EC2 space-delimited log stream pattern. Configure the rule to target an AWS Systems Manager Automation document that notifies the SNS topic and resets the log group.
Answer
Create a CloudWatch metric filter with the pattern `[timestamp, log_level, service_name = PaymentService, status_code = 503, execution_time]`. Configure a CloudWatch alarm based on this custom metric, and set the alarm action to send a notification to the Amazon SNS topic.
The correct configuration uses the standard bracket syntax `[...]` to define and filter space-delimited log entries. By listing the fields in order and using equality conditions (e.g., `service_name = PaymentService` and `status_code = 503`), CloudWatch Logs successfully isolates matching events. Once the metric is generated, a standard CloudWatch alarm can be configured to notify an Amazon SNS topic when the threshold is crossed.
Step-by-Step Solution
Key Concept
CloudWatch Logs Metric Filters and Alarms