Skip to content

Instantly share code, notes, and snippets.

@stack72
Created December 30, 2015 14:18
Show Gist options
  • Save stack72/ad97da2df376754e413a to your computer and use it in GitHub Desktop.
Save stack72/ad97da2df376754e413a to your computer and use it in GitHub Desktop.
var https = require('https');
var util = require('util');
exports.handler = function(event, context) {
try {
var message = JSON.parse(event.Records[0].Sns.Message);
var eventType = message.Event;
var autoScaleGroupName = message.AutoScalingGroupName;
var description = message.Description;
var cause = message.Cause;
var slackMessage = [
"*Event*: " + eventType,
"*Description*: " + description,
"*Cause*: " + cause,
].join("\n");
var postData = {
channel: "#notifications",
username: "AWS Bot",
text: "*" + autoScaleGroupName + "*",
attachments: [{ text: slackMessage, mrkdwn_in: ["text"] }]
};
var options = {
method: 'POST',
hostname: 'hooks.slack.com',
port: 443,
path: '/services/WEBHOOKURL'
};
var req = https.request(options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
context.done(null);
});
});
req.on('error', function(e) {
context.fail(e);
console.log('problem with request: ' + e.message);
});
req.write(util.format("%j", postData));
req.end();
} catch (e) {
context.fail(e)
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment