Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

send notification alert when AWS Lambda function has an error

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.

like image 933
Robert Avatar asked Mar 06 '17 13:03

Robert


People also ask

How do I monitor Lambda errors?

To do this, go to CloudWatch and click “Multi-function” under Insights/Lambda Insights. Here, we can observe metrics for multiple Lambda functions enabled, in this account, that have Lambda Insights enabled. In the Errors metric, we can identify the function “network-intensive-vpc” as having the highest error rate.

How do I send notifications to AWS Lambda?

The task is to send an email notification using AWS Lambda. First, you need to go to Amazon SNS and create a topic. You should create a topic, create a subscription and then publish to a topic. Then all the subscribers will get that notification(to Gmail or any other mail address).

Can you invoke a Lambda function using aws SNS notification?

Amazon SNS and AWS Lambda are integrated so you can invoke Lambda functions with Amazon SNS notifications. When a message is published to an SNS topic that has a Lambda function subscribed to it, the Lambda function is invoked with the payload of the published message.


1 Answers

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.

like image 78
Anthony Neace Avatar answered Sep 28 '22 13:09

Anthony Neace