我开始使用AWS Lambda,并试图从我的处理函数请求外部服务.根据this answer的说法,HTTP请求应该可以正常工作,而我还没有找到任何其他说明.(事实上,人们已经发布了code that use the Twilio API to send SMS条.)
我的处理程序代码是:
var http = require('http');
exports.handler = function(event, context) {
console.log('start request to ' + event.url)
http.get(event.url, function(res) {
console.log("Got response: " + res.statusCode);
}).on('error', function(e) {
console.log("Got error: " + e.message);
});
console.log('end request to ' + event.url)
context.done(null);
}
我在CloudWatch日志(log)中看到以下4行:
2015-02-11 07:38:06 UTC START RequestId: eb19c89d-b1c0-11e4-bceb-d310b88d37e2
2015-02-11 07:38:06 UTC eb19c89d-b1c0-11e4-bceb-d310b88d37e2 start request to http://www.google.com
2015-02-11 07:38:06 UTC eb19c89d-b1c0-11e4-bceb-d310b88d37e2 end request to http://www.google.com
2015-02-11 07:38:06 UTC END RequestId: eb19c89d-b1c0-11e4-bceb-d310b88d37e2
我希望这里还有一行:
2015-02-11 07:38:06 UTC eb19c89d-b1c0-11e4-bceb-d310b88d37e2 Got response: 302
但这是缺失的.如果我在本地机器上使用的基本部分没有 node 中的处理程序包装器,那么代码将按预期工作.
我使用的inputfile.txt
是用于invoke-async
呼叫的:
{
"url":"http://www.google.com"
}
处理程序代码中执行请求的部分似乎被完全跳过.我从request lib开始,后来又使用了plain http
来创建一个最小的示例.我还试图请求一个我控制的服务的URL来判断日志(log),但没有收到任何请求.
我完全被难住了.Is there any reason Node and/or AWS Lambda would not execute the HTTP request?