This is a lambda that will notify via email about alarms triggered by Cloudwatch Logs events using the SendGrid API.
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 fromTO_EMAIL
: The email address you'd like the notification to be sent toSENDGRID_API_KEY
: Your SendGrid API key. If necessary, you can create a new one here
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.
To run the lambda function locally using the contents of event.json
as the payload, run:
$ npm run local
To deploy the lambda to AWS, run:
$ npm run deploy
If you want to package the lambda as a zip file for manual upload to AWS, run:
$ npm run package
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: