Quantcast
Channel: Node.jsタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 9441

[Node] AWS Lambda標準ライブラリでPOST

$
0
0
こんにちは take-2405です。 AWS LambdaでSlack botを作成しました。 参考にさせていただいた記事 お急ぎの方用 const https = require('https'); const querystring = require('querystring'); . . . var post_data = querystring.stringify({channel:'',text:}, null); let options = { host: 'slack.com', path: '/api/chat.postMessage', port: 443, headers: { 'Content-Type': 'application/x-www-form-urlencoded', //他にtokenなど }, method: 'POST', }; var post_req = https.request(options, function(res) { res.setEncoding('utf8'); res.on('data', function (chunk) { console.log('Response: ' + chunk); context.succeed(); }); res.on('error', function (e) { console.log("Got error: " + e.message); context.done(null, 'FAILURE'); }); }); post_req.write(post_data); post_req.end(); 今回のPOST先 詳細 今回AWS Lambda上で定期的に動作するSlackBotを作成しました。 Slackにメッセージを送るためにはSlack APIへPOSTしなければならなかったのですが、requestを使ってPOSTをしようとすると Task timed out after 3.00 seconds とタイムアウトしてしまうように 原因を探ってみるとどうやらrequestを使用するためにはlocalでnpm installを行ってnode_moduleをzipファイルにしてアップロードする必要があるようです。 面倒ですよね、、 なんとか標準ライブラリを使用してブラウザでコードを書いてLambdaからPOSTしようと思い今回調べてみました。

Viewing all articles
Browse latest Browse all 9441

Trending Articles