Created
January 20, 2017 08:12
-
-
Save tokutoku3/98036e372af3fa1c69c7bcef4ac2aad6 to your computer and use it in GitHub Desktop.
Lambda(Node.js v4.3)でSlackに通知を送る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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