AWS Lambda上的Highcharts导出服务器

AWS Lambda上的Highcharts导出服务器,lambda,highcharts,Lambda,Highcharts,是否有人成功创建了在AWS Lambda上运行的highcharts导出服务器?如果是这样,他们可能愿意共享一个示例部署包 总体目标是能够将图像类型和图表选项作为有效负载传递给lambda,并让它返回图像 到目前为止,我已经做了以下工作: # Created a folder and moved into it cd ../highchart_export_server # Im building Phantom on OSX do I need to set these to get Pha

是否有人成功创建了在AWS Lambda上运行的highcharts导出服务器?如果是这样,他们可能愿意共享一个示例部署包

总体目标是能够将图像类型和图表选项作为有效负载传递给lambda,并让它返回图像

到目前为止,我已经做了以下工作:

# Created a folder and moved into it
cd ../highchart_export_server

# Im building Phantom on OSX do I need to set these to get Phantom to build
# for linux
export PHANTOMJS_PLATFORM="linux"
export PHANTOMJS_ARCH="x64"

# Created a new package and install highcharts per docs
npm init
npm install highcharts-export-server

# Create an index handler -> See the content of that file below

# zip the package up as a deployment and upload it to lambda
zip -r function.zip .

index.js
//包括导出器模块
const exporter=require('highcharts-export-server');
exports.handler=异步(事件)=>{
变量类型=event.body.type;
console.log('Type:'+Type);
//导出设置
变量导出设置={
类型:event.format,
选项:event.options;
//建立一个幻影工作人员库
exporter.initPool();
//执行导出
/*
导出设置对应于所述的可用CLI参数
在上面
*/
exporter.export(导出设置,函数(err,res){
如果(错误){
console.log(err.stack);
}
//导出结果现在是res。
//如果输出不是PDF或SVG,则将使用base64编码(res.data)。
//如果输出是PDF或SVG,它将包含一个文件名(res.filename)。
//完成后杀死池,并退出应用程序
exporter.killPool();
过程。退出(1);
});
常数响应={
状态代码:200,
主体:事件,
};
返回响应;
};
当我测试函数时,我得到以下错误:

START RequestId: 97e615c4-5e42-457e-8c8a-02e7001957f5 Version: $LATEST
2019-07-18T15:20:57.128Z    97e615c4-5e42-457e-8c8a-02e7001957f5    ERROR   Uncaught Exception  {"errorType":"Error","errorMessage":"write EPIPE","code":"EPIPE","stack":["Error: write EPIPE","    at WriteWrap.afterWrite [as oncomplete] (net.js:779:14)"],"errno":"EPIPE","syscall":"write"}
2019-07-18T15:20:57.207Z    97e615c4-5e42-457e-8c8a-02e7001957f5    INFO    uncaughtException: { Error: write EPIPE
    at WriteWrap.afterWrite [as oncomplete] (net.js:779:14)
  errno: 'EPIPE',
  code: 'EPIPE',
  syscall: 'write',
  [Symbol(aws.lambda.Timestamp)]: 2019-07-18T15:20:57.128Z,
  [Symbol(aws.lambda.RequestId)]: '97e615c4-5e42-457e-8c8a-02e7001957f5' }
2019-07-18T15:20:57.247Z    97e615c4-5e42-457e-8c8a-02e7001957f5    INFO    Thu Jul 18 2019 15:20:57 GMT+0000 (Coordinated Universal Time) [error] phantom worker 1 error - /var/task/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
2019-07-18T15:20:57.247Z    97e615c4-5e42-457e-8c8a-02e7001957f5    INFO    Thu Jul 18 2019 15:20:57 GMT+0000 (Coordinated Universal Time) [error] phantom worker 2 error - /var/task/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
2019-07-18T15:20:57.247Z    97e615c4-5e42-457e-8c8a-02e7001957f5    INFO    Thu Jul 18 2019 15:20:57 GMT+0000 (Coordinated Universal Time) [error] phantom worker 3 error - /var/task/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
2019-07-18T15:20:57.247Z    97e615c4-5e42-457e-8c8a-02e7001957f5    INFO    Thu Jul 18 2019 15:20:57 GMT+0000 (Coordinated Universal Time) [error] phantom worker 4 error - /var/task/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
2019-07-18T15:20:57.248Z    97e615c4-5e42-457e-8c8a-02e7001957f5    INFO    Thu Jul 18 2019 15:20:57 GMT+0000 (Coordinated Universal Time) [error] phantom worker 5 error - /var/task/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
2019-07-18T15:20:57.248Z    97e615c4-5e42-457e-8c8a-02e7001957f5    INFO    Thu Jul 18 2019 15:20:57 GMT+0000 (Coordinated Universal Time) [error] phantom worker 6 error - /var/task/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
2019-07-18T15:20:57.248Z    97e615c4-5e42-457e-8c8a-02e7001957f5    INFO    Thu Jul 18 2019 15:20:57 GMT+0000 (Coordinated Universal Time) [error] phantom worker 7 error - /var/task/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
2019-07-18T15:20:57.248Z    97e615c4-5e42-457e-8c8a-02e7001957f5    INFO    Thu Jul 18 2019 15:20:57 GMT+0000 (Coordinated Universal Time) [error] phantom worker 8 error - /var/task/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
2019-07-18T15:20:57.268Z    97e615c4-5e42-457e-8c8a-02e7001957f5    INFO    undefined
END RequestId: 97e615c4-5e42-457e-8c8a-02e7001957f5
REPORT RequestId: 97e615c4-5e42-457e-8c8a-02e7001957f5  Duration: 620.04 ms Billed Duration: 700 ms     Memory Size: 128 MB Max Memory Used: 81 MB  
RequestId: 97e615c4-5e42-457e-8c8a-02e7001957f5 Process exited before completing request

根据错误,它看起来像是缺少了
libfontconfig.so.1
,但我找不到任何方法将其添加到依赖项中。

对此,我创建了一个Github repo,其中包含一个专门用于将Highcharts导出服务器部署到Lamdba上的项目

Github:

我已经为那些希望从头开始构建的人提供了详细的说明,以及一个可以直接上传到Lambda的预构建zip

此项目包含对注释中提到的缺少字体的修复


我也有同样的任务,将highcharts导出服务器放在lambda上。所有的一切都是由于您的回答和所附的zip文件,除了一件事。图片生成成功,但完全没有字体。您能告诉我问题出在哪里吗?我不知道该怎么看,从哪里推。@Nick请查看位于的新项目。它包含字体问题的修复。我还获得了一项任务,以在Lambda中运行导出服务器。修复依赖项和字体后,我可以获得图像(png、jpg)。但我很好奇为什么没有生成PDF文件。执行成功,但没有本地文件。我也进行了递归搜索,但找不到它。您能在Lambdas中生成PDF吗?@YuriiMaksimov,如repo文档中所述,默认情况下这不是返回PDF>的设置。Lambda函数无法直接返回文件。因此,如果您是要将图表转换为PDF或SVG,您需要创建一些代码来处理将highcharts创建的文件写入字节[](或其他机制,如S3)@tarka是的,我理解,但问题是文件本身没有创建。因此,没有生成字节[]的源代码