有人成功创建了在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
//Include the exporter module
const exporter = require('highcharts-export-server');
exports.handler = async (event) => {
var type = event.body.type;
console.log('Type: ' + type);
//Export settings
var exportSettings = {
type: event.format,
options: event.options;
//Set up a pool of PhantomJS workers
exporter.initPool();
//Perform an export
/*
Export settings corresponds to the available CLI arguments described
above.
*/
exporter.export(exportSettings, function (err, res) {
if (err) {
console.log(err.stack);
}
//The export result is now in res.
//If the output is not PDF or SVG, it will be base64 encoded (res.data).
//If the output is a PDF or SVG, it will contain a filename (res.filename).
//Kill the pool when we're done with it, and exit the application
exporter.killPool();
process.exit(1);
});
const response = {
statusCode: 200,
body: event,
};
return response;
};
测试功能时出现此错误:
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存储库,其中有一个专门用于将Highcharts导出服务器部署到Lamdba上的专用项目。
Github:https://github.com/tarkal/highchart-lambda-export-server
[我已经为希望从头开始构建的用户提供了详细的说明,以及可以直接上传到Lambda的预构建zip。
此项目包含对注释中提到的丢失字体的修复。