Soru

Zorluk: KolayMonitoring and Analyzing Logs with Amazon CloudWatch

A developer needs to monitor a serverless application's log group in Amazon CloudWatch Logs for database connection errors. The application logs errors in the format: `[ERROR] DatabaseConnectionError: Connection timed out`. The developer wants to count these errors and send notifications when they occur. Which TWO actions should the developer take to achieve this?

  1. Create an Amazon CloudWatch Logs metric filter on the log group using the filter pattern "DatabaseConnectionError".Cevap
  2. Create an Amazon CloudWatch alarm based on the custom metric published by the metric filter to trigger notifications when the threshold is exceeded.Cevap
  3. C
    Define the metric filter using the query syntax "fields @timestamp, @message | filter @message like /DatabaseConnectionError/".
  4. D
    Increase the execution timeout of the Lambda function so that the CloudWatch Logs service has sufficient time to poll the active execution context.
  5. E
    Configure an IAM trust policy on the log group that allows the Lambda function execution role to assume the CloudWatch Logs service principal.

Cevap

Create an Amazon CloudWatch Logs metric filter on the log group using the filter pattern "DatabaseConnectionError" and create an Amazon CloudWatch alarm based on the custom metric to trigger notifications when the threshold is exceeded.
The correct approach involves creating a CloudWatch Logs metric filter to search for the specific pattern 'DatabaseConnectionError' in incoming log events. This filter increments a custom CloudWatch metric. Then, a CloudWatch alarm must be configured on that custom metric to trigger an alarm state and notify the team (e.g., via SNS) when the occurrence threshold is crossed.

Adım Adım Çözüm

1
Analyze the log structure to identify the term to monitor.
The target term "DatabaseConnectionError" is identified within the log pattern.
The filter pattern needs to match this specific string in the log stream.
2
Configure the metric filter with the pattern.
A metric filter is created on the log group that increments a custom metric name whenever "DatabaseConnectionError" appears.
Metric filters translate log data into numeric metrics.
3
Create a CloudWatch alarm.
An alarm is configured to monitor the custom metric and send notifications (e.g., via Amazon SNS) when the error rate exceeds the defined limit.
Alarms are required to detect threshold breaches and initiate notification actions.

Anahtar Kavram

Configuring CloudWatch Logs metric filters and alarms to detect and alert on specific patterns in application logs.
Bu soruyu puanla