gpt4 book ai didi

lambda - AWS Lambda 上的 Highcharts 导出服务器

转载 作者:行者123 更新时间:2023-12-02 16:54:18 26 4
gpt4 key购买 nike

有人成功创建了一个运行在 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。

This project contains a fix for the missing fonts mentioned in the comments.

关于lambda - AWS Lambda 上的 Highcharts 导出服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57097890/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com