Ale*_*res 8 lambda amazon-web-services node.js npm phantomjs
我试图让我的 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);
}
});
Run Code Online (Sandbox Code Playgroud)
我期望结果是一个 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
Run Code Online (Sandbox Code Playgroud)
我相信我现在要么必须 1) 弄清楚如何在没有此依赖项的情况下运行 phantomjs 或 2) 弄清楚如何将此依赖项安装到我的 Lambda 函数的“服务器”
也许有一个以前版本的 phantomjs 可以在没有这种依赖性的情况下为我提供我想要的功能?没有把握
有谁知道我该如何解决这个问题?谢谢!
小智 -1
在您的控制台中您可以输入:
$ sudo yum install fontconfig
Run Code Online (Sandbox Code Playgroud)
这将安装所需的库。
| 归档时间: |
|
| 查看次数: |
2579 次 |
| 最近记录: |