相关疑难解决方法(0)

为什么此HTTP请求无法在AWS Lambda上运行?

我开始使用AWS Lambda,我正在尝试从我的处理程序函数请求外部服务.根据这个答案,HTTP请求应该可以正常工作,我没有找到任何其他说明的文档.(事实上​​,人们已经发布了使用Twilio API发送短信的代码.)

我的处理程序代码是:

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);
}
Run Code Online (Sandbox Code Playgroud)

我在CloudWatch日志中看到以下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
Run Code Online (Sandbox Code Playgroud)

我期待那里有另一条线:

2015-02-11 07:38:06 …
Run Code Online (Sandbox Code Playgroud)

httprequest amazon-web-services node.js aws-lambda

74
推荐指数
7
解决办法
10万
查看次数