Cloudwatch alarm for notifying lambda errors

I have created Cloudwatch alarm to notify errors through SNS. Alarm always indicates INSUFFICIENT_DATA even though there are Invocation errors according to the graph associated with the lambda function.

This is the Cloudformation configuration for the Alarm

      LambdaErrorAlarm:
      Type: AWS::CloudWatch::Alarm
      DependsOn: NotificationSendLambdaFunction
      Properties:
        AlarmName: ErrorLogNotification
        AlarmDescription: When Lambda error occurs it will be notified through SNS
        Namespace: 'AWS/Lambda'
        MetricName: Errors
        Dimensions:
          - Name: NotificationSendLambdaFunction
            Value: ${self:service}-${self:provider.stage}-notification-send
        Statistic: Sum
        ComparisonOperator: GreaterThanThreshold
        Threshold: 0
        Period: 60
        EvaluationPeriods: 1
        AlarmActions:
          - Ref: ErrorLogNotificationSns

Another thing I wanted ask is how to get the Lambda function Resource name within the serveless.yml file?
For example, I have given my lambda function configuration below and I need to get it’s resource name for above DependOn parameter. For now I have taken the name from cloud formation template stack as NotificationSendLambdaFunction and hard coded for DependOn parameter.

NotificationSend:
    handler: handlers/notification.send
    memory: 512
    timeout: 30
    events:
      - http:
          path: notification/send
          method: GET
      - schedule:
          rate: rate(24 hours)
1 Like

Personally, when I tried to figure out what I wanted to do with cloudwatch alarms, I came across the serverless-plugin-aws-alerts plugin:

It works really well, and I haven’t had any issues with it. In your serverless.yml file, you simply add the following:

plugins:
  - serverless-plugin-aws-alerts

custom:
  alerts:
    topics:
      alarm: <sns topic arn you want to send alert to>
    alarms:
      - functionErrors

Then, in each function you want to add alerts, just add an ‘alarms’ field:

functions:
  demo-function:
    handler: demo-function.main
    events:
      - http:
          path: demo-function-path
          method: post
    alarms:
      - functionErrors

You do need to create a SNS topic to publish the alerts to, and then you can subscribe with your email to get the alerts sent to you.

Another option:

More recently, I learned about Dashbird. I just started using it, but it also takes care of error notifications:

The really killer feature in my opinion, is that you can click on the error, and it will pull the specific cloudwatch log associated with that invocation. Which was previously a super big issue with hunting down errors. You have to pay to use it, but if you are using it in a business setting, I think it is easily worth it.

1 Like

Thanks for responding, I figured it out and fixed. It was a syntax issue and I have given the correct one below,

    LambdaErrorAlarm:
      Type: AWS::CloudWatch::Alarm
      Properties:
        AlarmName: ErrorLogNotification
        AlarmDescription: When Lambda error occurs it will be notified through SNS
        Namespace: 'AWS/Lambda'
        MetricName: Errors
        Dimensions:
          - Name: FunctionName
            Value: ${self:service}-${self:provider.stage}-NotificationSend
        Statistic: Minimum
        ComparisonOperator: GreaterThanThreshold
        Threshold: 0
        Period: 60
        EvaluationPeriods: 1
        AlarmActions:
          - Ref: ErrorLogNotificationSns
1 Like