-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathsnsToSlack.js
43 lines (36 loc) · 1.1 KB
/
snsToSlack.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* eslint-disable @typescript-eslint/no-var-requires */
var https = require('https');
var util = require('util');
exports.handler = function (event, context) {
console.log(JSON.stringify(event, null, 2));
console.log('From SNS:', event.Records[0].Sns.Message);
var postData = {
channel: '#site-monitoring',
username: 'AWS SNS Alert',
text: '*Gallformers is Down!!!*',
icon_emoji: ':scream_cat:',
};
postData.attachments = [
{
color: 'danger',
text: 'Action is needed NOW!',
},
];
var options = {
method: 'POST',
hostname: 'hooks.slack.com',
port: 443,
path: 'MUST GET PATH TO SLACK INTEGRATION WITH SECRET KEY AND PASTE IT HERE!!!',
};
var req = https.request(options, function (res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
context.done(null);
});
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
});
req.write(util.format('%j', postData));
req.end();
};