Skip to content

Instantly share code, notes, and snippets.

@tokutoku3
Created January 20, 2017 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tokutoku3/98036e372af3fa1c69c7bcef4ac2aad6 to your computer and use it in GitHub Desktop.
Save tokutoku3/98036e372af3fa1c69c7bcef4ac2aad6 to your computer and use it in GitHub Desktop.
Lambda(Node.js v4.3)でSlackに通知を送る
console.log('Loading function');
const https = require('https');
const url = require('url');
const slack_url = process.env.slack_url;
const slack_req_opts = url.parse(slack_url);
slack_req_opts.method = 'POST';
slack_req_opts.headers = {'Content-Type': 'application/json'};
exports.handler = function (event, context) {
var req = https.request(slack_req_opts, function (res) {
if (res.statusCode === 200) {
context.succeed('posted to slack');
} else {
context.fail('status code: ' + res.statusCode);
}
});
req.on('error', function (e) {
console.log('problem with request: ' + e.message);
context.fail(e.message);
});
// この辺で適当にslack postするテキストを調整する.
var str = "lambda test!";
req.write(JSON.stringify({text: str}));
req.end();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment