【发布时间】:2017-06-12 15:45:45
【问题描述】:
我正在尝试在 AWS Lambda 中创建函数,该函数返回给定网站的 html。那是我的代码:
console.log('Loading function');
exports.handler = (event, context, callback) => {
var util = require("util"),
http = require("http");
var options = {
host: "www.nyuad.nyu.edu/en/news-events/abu-dhabi-events.html",
port: 80,
path: "/"
};
var content = "";
var req = http.request(options, function(res) {
res.setEncoding("utf8");
res.on("data", function (chunk) {
content += chunk;
});
res.on("end", function () {
util.log(content);
callback(null, content);
});
});
req.end();
};
它非常适合 'www.google.com' 作为 options 中的 host 参数,但是当我尝试更复杂时,类似于代码中的给定参数,我得到一个错误:
Error: getaddrinfo ENOTFOUND www.nyuad.nyu.edu/en/news-events/abu-dhabi-events.html www.nyuad.nyu.edu/en/news-events/abu-dhabi-events.html:80
at errnoException (dns.js:26:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:77:26)
【问题讨论】:
标签: node.js amazon-web-services aws-lambda