简体   繁体   English

AWS Lambda nodejs 函数抛出异常以使用 html-pdf 生成 html 到 pdf

[英]AWS Lambda nodejs function throwing exception to generate html to pdf using html-pdf

We have created AWS Lambda function to generate html to pdf dynamically in nodejs4.3 eun environment using html-pdf library.我们已经创建了AWS Lambda函数来使用 html-pdf 库在nodejs4.3 eun 环境中动态生成 html 到 pdf。

That function is working well in workstation.该功能在工作站中运行良好。 We are getting the below exception when test in AWS Lambda .AWS Lambda测试时,我们收到以下异常。

Error Details:错误详情:

{ "errorMessage": "spawn /var/task/node_modules/phantomjs-prebuilt/lib/phantom\\bin\\phantomjs.exe ENOENT", "errorType": "Error", "stackTrace": [ "exports._errnoException (util.js:870:11)", "Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)", "onErrorNT (internal/child_process.js:344:16)", "nextTickCallbackWith2Args (node.js:437:9)", "process._tickDomainCallback (node.js:392:17)" ] { "errorMessage": "spawn /var/task/node_modules/phantomjs-prebuilt/lib/phantom\\bin\\phantomjs.exe ENOENT", "errorType": "Error", "stackTrace": [ "exports._errnoException (util. js:870:11)", "Process.ChildProcess._handle.onexit (internal/child_process.js:178:32)", "onErrorNT (internal/child_process.js:344:16)", "nextTickCallbackWith2Args (node.js) :437:9)", "process._tickDomainCallback (node.js:392:17)" ]

Can any one advise me, how to resolve this issue.任何人都可以建议我,如何解决这个问题。

The error is raised because you don't have PhantomJS binary 由于没有PhantomJS二进制文件而引发错误

/var/task/node_modules/phantomjs-prebuilt/lib/phantom\\bin\\phantomjs.exe /var/task/node_modules/phantomjs-prebuilt/lib/phantom\\bin\\phantomjs.exe

that is supposed to save an HTML page to PDF. 应该将HTML页面保存为PDF。

But even if you would have that binary packed with you Lambda function, it still wouldn't work: the *.exe extension clearly suggests it's a Microsoft Windows executable. 但是,即使您随Lambda函数一起打包了该二进制文件,也仍然无法使用:*。exe扩展名显然表明它是Microsoft Windows可执行文件。 You will need the Linux version to run in AWS Lambda. 您将需要Linux版本才能在AWS Lambda中运行。

您应该在 *nix 机器上安装“phantomjs-prebuilt”和“html-pdf”包并部署

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM