Easily deploy a NodeJS or Python function for handling Serverless Insight Alert Notifications.
$ npm install -g serverless
$ mkdir notification-forwarder && cd notification-forwarder
The directory should look something like this:
|- handler.js # OR handler.py
|- serverless.yml
|- .env # your AWS api keys
the .env
file should look like this
AWS_ACCESS_KEY_ID=XXX
AWS_SECRET_ACCESS_KEY=XXX
The handler.js
or handler.py
file should contain a function to handle an alert notification event from
Serverless Insights.
module.exports.alert = (notification) => {
console.log('got notification', notification);
}
def alert(notification):
print('got notification', notification)
Configure your serverless.yml
as follows:
# serverless.yml
name: notification-handler
stage: dev
notificationHandler:
component: '@serverless/notification-handler'
inputs:
code: .
handler: handler.alert
env:
FOOBAR: ${env.FOOBAR} # Optional, set any env vars for your code
$ serverless
Paste the ARN printed in the output of the previous step into the SNS notification configuration on dashboard.serverless.com for your app.
Checkout the Serverless Components repo for more information.