AWS CloudWatch Metric Filter Not Triggering Alarms for Lambda Function Metrics
I've searched everywhere and can't find a clear answer... I've been banging my head against this for hours. I'm facing an issue where my CloudWatch metric filter is not triggering alarms for my Lambda function metrics as expected. I've set up a metric filter to monitor the 'Duration' of my Lambda function, which is invoked via an API Gateway. The filter pattern looks like this: ```json { $.duration > 2000 } ``` However, despite my Lambda function frequently exceeding the 2 seconds threshold, the alarm doesn't seem to activate. I've ensured that the filter is associated with the correct log group for the Lambda function with the following settings: ```json { "FilterName": "LongExecutionFilter", "LogGroupName": "/aws/lambda/my-function-name", "FilterPattern": "{ $.duration > 2000 }" } ``` I also created an alarm that should trigger an SNS notification when the metric exceeds this threshold: ```json { "AlarmName": "HighDurationAlarm", "MetricName": "Duration", "Namespace": "AWS/Lambda", "Statistic": "Average", "Period": 60, "EvaluationPeriods": 1, "Threshold": 2000, "ComparisonOperator": "GreaterThanThreshold", "AlarmActions": ["arn:aws:sns:us-west-2:123456789012:my-SNS-topic"] } ``` I checked the CloudWatch Logs and confirmed that the Lambda function is running with a duration above 2000 ms on multiple invocations, but the metric filter does not seem to log any matches. I've also looked into the IAM permissions for the CloudWatch Logs and the Lambda function, ensuring that they have the necessary access rights. Could there be something I'm missing in the configuration, or is there a delay in how CloudWatch processes these metrics? Any insights would be greatly appreciated. This is part of a larger application I'm building. What's the best practice here? How would you solve this? My team is using Json for this REST API.