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?
- Create an Amazon CloudWatch Logs metric filter on the log group using the filter pattern "DatabaseConnectionError".Answer
- Create an Amazon CloudWatch alarm based on the custom metric published by the metric filter to trigger notifications when the threshold is exceeded.Answer
- CDefine the metric filter using the query syntax "fields @timestamp, @message | filter @message like /DatabaseConnectionError/".
- DIncrease the execution timeout of the Lambda function so that the CloudWatch Logs service has sufficient time to poll the active execution context.
- EConfigure an IAM trust policy on the log group that allows the Lambda function execution role to assume the CloudWatch Logs service principal.
Answer
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.
Step-by-Step Solution
Key Concept
Configuring CloudWatch Logs metric filters and alarms to detect and alert on specific patterns in application logs.