Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

AWS lambda function to notify via email about CloudWatch logs alarms using SendGrid

License

Notifications You must be signed in to change notification settings

mblink/cloudwatch-logs-lambda-notifier

Repository files navigation

CloudWatch Logs lambda notifier

Build Status

This is a lambda that will notify via email about alarms triggered by Cloudwatch Logs events using the SendGrid API.

Setup

Clone the repository, then run the following:

$ npm install
$ cp .env.sample .env
$ cp deploy.env.sample deploy.env
$ cp event.json.sample event.json

In .env, replace the value of AWS_ROLE_ARN with the value you create below in "Create a role". Replace other config values as necessary,

In deploy.env, add your own secret values to use when sending the email notification with SendGrid. The values are:

  • FROM_EMAIL: The email address you'd like the notification to appear to be sent from
  • TO_EMAIL: The email address you'd like the notification to be sent to
  • SENDGRID_API_KEY: Your SendGrid API key. If necessary, you can create a new one here

Create a role

In the IAM roles console, create a new role. When you're prompted to choose a role type, select "AWS Lambda." When you're prompted to attach policies, attach the one named "CloudWatchLogsFullAccess."

Once you've finished creating the role, copy the ARN and put it in .env as mentioned above.

Run locally

To run the lambda function locally using the contents of event.json as the payload, run:

$ npm run local

Deploy

To deploy the lambda to AWS, run:

$ npm run deploy

Package

If you want to package the lambda as a zip file for manual upload to AWS, run:

$ npm run package

Subscribe to a CloudWatch alarm

In the CloudWatch alarms console, create a new alarm for your log stream and specify the SNS topic that it should send notifications to (you'll have the option to create a new one).

Once that's done, find your SNS topic's ARN in the SNS topics console and create a new subscription in the SNS subscriptions console. Your subscription should look like this:

subscription

About

AWS lambda function to notify via email about CloudWatch logs alarms using SendGrid

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published