17

I have a AWS Lambda function running some process in my infrastructure. The Lambda is triggered every 8 hours using a CloudWatch rule. I am trying to raise a notification if any error happens into the Lambda process. I tried to use SES but that service is not available in that Region.

I will like to know any suggestions for this problem:

How to setup notifications when an error occurs in my Lambda functions ?

I am looking for suggestions. This questions never asked for doing my task. I will appreciate any official documentation but either way, any help is welcome.

1 Answer 1

25

Some suggestions:

Dead Letter Queues:

If your error causes failed invocations, you can use a Lambda Dead Letter Queue to send the event to an SNS topic or an SQS queue. If you send it to an SNS topic, you can directly subscribe to the topic via SNS or Email to get notified any time a message is published to that topic.

Multi-region SES:

If you're really set on using SES directly, SES clients can be instantiated with an explicit region provided -- as long as your lambda's execution role has the appropriate permissions, you can send email to SES from a different region. Here's documentation for instantiating the JS SES Client.

CloudWatch Logs:

If your error does not cause the invocation to fail, another option is using a CloudWatch Logs metric filter to aggregate failures and potentially alarm on them. If you're using NodeJS, you can simply log out via console.log(), console.error(), etc. and it will be written out to CWLogs. More details here.

You can subscribe an SNS topic to CloudWatch Alarms, and notify yourself in the same way as the DLQ.


As you gain experience with the error and learn how to process common errors, you could also subscribe another lambda to the SNS topic from the DLQ/CWLogs example to process it as it happens.

4
  • Thank you for your answer. I read you answer and I did a search about the metric filter and I created the metric filter but it is raising the notification just one time. I used my email and it sends the notification email error just the first time when the errors happen. I will like to know why is not raising the email more than one. If you have any clue?
    – Robert
    Commented Mar 6, 2017 at 16:15
  • 3
    Yes; for a CloudWatch Alarm, if your metric exceeds the alarm threshold in the given alarm period, you'll get a single email noting that the alarm has been tripped. So if you wrote to the metric 10 times in a single period and the alarm trips for value = 1, you'll get a single alarm notification. If you set your alarm period to something sufficiently low (for your use case of only running once every 8 hours there is no harm in setting the alarm threshold to be very low, like metric value > 1 for 1 period of 5 minutes), you'll see alarms across multiple periods. Commented Mar 6, 2017 at 16:30
  • Well, was about time and thresholds. After a few minutes the alarm return to previous state if everything is going well. Thank you
    – Robert
    Commented Mar 6, 2017 at 18:08
  • 1
    Relative to the "CloudWatch Logs" option, there is an ErrorProcessor example from AWS that you may find it relevant
    – r.pedrosa
    Commented Oct 23, 2019 at 11:29