Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add CloudWatch Logs to To SNS Email

I am trying to send alarm emails when some errors are thrown in an AWS Lambda function. I could configure CloudWatch Alarms to send emails via SNS topics by creating an Alarm. If I have a python exception, the alarm is thrown an email is sent. I can see the exception data in the Cloudwatch Logs. However, the emails do not contain the exception data. They are only showing up in the Logs as as follows:

{
"errorMessage": "Example Test Failure",
"errorType": "Exception",
"stackTrace": [
    [
    "/var/task/lambda_function.py",
    7,
    "lambda_handler",
    "raise Exception('Example Test Failure')"
    ]
  ]
}

Is there a way to add this errorMessage to the text of the SNS email ?

like image 660
exifguy Avatar asked Jan 19 '18 20:01

exifguy


People also ask

How do I send an email from CloudWatch logs?

Create a metric filter that monitors your log group for specific pattern. Then create a CloudWatch alarm based on a new metric and configure it with an SNS action. Then simply subscribe your email to that SNS topic. All of this can be easily done via CloudFormation(Metric filter, Alarm, SNS).

How do I enable CloudWatch on SNS?

To enable and view CloudWatch Logs for your SMS messagesSign in to the Amazon SNS console . In the console menu, set the region selector to a region that supports SMS messaging. On the navigation panel, choose Text messaging (SMS).

Can CloudWatch trigger SNS?

AWS CloudWatch works with the AWS SNS service to send notifications to users either through email or SMS. It can also trigger other actions using HTTPS calls, SQS, and Lambda functions.

Can CloudWatch subscribe to SNS?

Amazon CloudWatch uses Amazon SNS to send email. First, create and subscribe to an SNS topic. When you create a CloudWatch alarm, you can add this SNS topic to send an email notification when the alarm changes state. For more information, see the Amazon Simple Notification Service Getting Started Guide.


1 Answers

You can do that by streaming the CloudWatch logs to an AWS Lambda that sends a notification to SNS.

like image 70
TheNavigat Avatar answered Sep 26 '22 00:09

TheNavigat