【发布时间】:2018-05-16 04:00:12
【问题描述】:
我正在尝试让我的 lambda 函数使用 phantomjs,但是它一直遇到缺少依赖项的错误:libfontconfig / fontconfig。在我的 Centos VPS 上,当我安装 fontconfig (dnf install fontconfig -y) 时,我的代码运行良好。但是,在 lambda 上运行时,我无法弄清楚如何让这个库与我的函数一起运行。
这是我的代码:(试图通过使用 phantomjs 的 AliExpress 包获得最畅销的产品)
const aliExpress = require('aliexpress');
exports.handler = (event, context, callback) => {
console.log('Handler ran!');
aliExpress.BestSelling.get().then((goods) => {
console.log('Found results!');
const urls = [];
for(let index in goods) {
const url = goods[index].url;
urls.push(url);
}
console.log('Returning URLs:');
console.log(urls);
callback(null, urls);
}).catch((err) => {
console.log('Error:');
console.log(err);
callback(err);
});
};
// For testing on VPS
exports.handler(null, null, (err, result) => {
if(err) {
console.log('Err:');
console.log(err);
} else {
console.log('Result:');
console.log(result);
}
});
我希望结果是 AliExpress URL 的数组,每当我在 VPS 上安装 fontconfig 运行它时都会发生这种情况。但是,在我的 lambda 函数和没有安装 fontconfig 的 VPS 上,我收到了这个错误:
Handler ran!
(node:1966) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: Error reading from stdin: Error: write EPIPE
(node:1966) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
error: /home/function/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs: error while loading shared libraries: libfontconfig.so.1: cannot open shared object file: No such file or directory
我相信我现在要么必须 1) 弄清楚如何在没有此依赖项的情况下运行 phantomjs,要么 2) 弄清楚如何将此依赖项安装到我的 Lambda 函数的“服务器”
也许以前版本的 phantomjs 可以提供我想要的功能而无需这种依赖?不确定
有人知道我该如何解决这个问题吗?谢谢!
【问题讨论】:
-
尝试提供预编译版本而不是安装它,例如phantomjs.org/download.html
-
另外,您可能应该知道 PhantomJS 不再被开发/维护。除此之外,您没有获得任何嵌入式 Webkit 引擎的安全更新。托管一个任意过时的基于 Webkit 并连接到第三方网站的东西可能不是一个好主意——尤其是当它遇到广告(恶意软件)时。
标签: node.js amazon-web-services lambda npm phantomjs