Search code examples
node.jsamazon-web-servicesphantomjsaws-lambda

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.

That function is working well in workstation. We are getting the below exception when test in 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)" ]

Can any one advise me, how to resolve this issue.


Solution

  • The error is raised because you don't have PhantomJS binary

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

    that is supposed to save an HTML page to 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. You will need the Linux version to run in AWS Lambda.