# Cloudwatch alarm for notifying lambda errors

**URL:** <https://forum.serverless.com/t/cloudwatch-alarm-for-notifying-lambda-errors/3906>\
**Category:** Serverless Framework\
**Tags:** aws, lambda\
**Created:** [March 1, 2018, 6:50am UTC](https://forum.serverless.com/t/cloudwatch-alarm-for-notifying-lambda-errors/3906 "2018-03-01T06:50:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdesilva](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mdesilva](https://forum.serverless.com/u/mdesilva)\
**Post date:** [March 1, 2018, 6:50am UTC](https://forum.serverless.com/t/cloudwatch-alarm-for-notifying-lambda-errors/3906/1 "2018-03-01T06:50:23Z")

</div>

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)
```

---

<div class="post-metadata">

**Author:** ![thehardness](https://avatars.discourse-cdn.com/v4/letter/t/ee7513/32.png) [@thehardness](https://forum.serverless.com/u/thehardness)\
**Post date:** [March 1, 2018, 5:50pm UTC](https://forum.serverless.com/t/cloudwatch-alarm-for-notifying-lambda-errors/3906/2 "2018-03-01T17:50:06Z")

</div>

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

> **[serverless-plugin-aws-alerts](https://www.npmjs.com/package/serverless-plugin-aws-alerts)**
>
> \[!\[NPM version\]\[npm-image\]\]\[npm-url\] \[!\[Build Status\]\[travis-image\]\]\[travis-url\] \[!\[Dependency Status\]\[daviddm-image\]\]\[daviddm-url\] \[!\[codecov\]\[codecov-image\]\]\[codecov-url\]. Latest version: 1.7.4, last published: 7 months ago. Start using...

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

```auto
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:

```auto
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:

> **[Serverless Observability and Intelligence Platform](https://dashbird.io/)**
>
> Enhanced serverless monitoring, automated alerting and actionable Well-Architected insights for AWS managed services. Try it free for 14 days.

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.

---

<div class="post-metadata">

**Author:** ![mdesilva](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mdesilva](https://forum.serverless.com/u/mdesilva)\
**Post date:** [March 5, 2018, 11:51pm UTC](https://forum.serverless.com/t/cloudwatch-alarm-for-notifying-lambda-errors/3906/3 "2018-03-05T23:51:38Z")

</div>

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
```
