pdf-creator-node icon indicating copy to clipboard operation
pdf-creator-node copied to clipboard

Working on local but not as AWS Lambda code

Open lahoti-piyush opened this issue 1 year ago • 5 comments

AWS Lambda Runtime: Node.js 18.x

spawn /var/task/node_modules/phantomjs-prebuilt/lib/phantom\bin\phantomjs.exe ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn /var/task/node_modules/phantomjs-prebuilt/lib/phantom\\bin\\phantomjs.exe',
  path: '/var/task/node_modules/phantomjs-prebuilt/lib/phantom\\bin\\phantomjs.exe',
  spawnargs: [
    '--local-url-access=false',
    '--local-url-access=false',
    '/var/task/node_modules/html-pdf/lib/scripts/pdf_a4_portrait.js'
  ]
}

lahoti-piyush avatar Jun 12 '23 10:06 lahoti-piyush

It would help if you run npm rebuild on the server side to build phantomjs binaries for specific platforms. I have Linux VPS and it's helped me. P.s.: I've no experience with AWS Lambda, so I can't provide direct instructions.

muhammadyusuf-kurbonov avatar Jun 13 '23 04:06 muhammadyusuf-kurbonov

you will need to add a phantom js binary and provide the path, along with that, you need to provide the path to pdf_a4_portrait.js file

childProcessOptions: {
      env: {
        OPENSSL_CONF: "/dev/null"
      }
    },
    localUrlAccess: true,
    phantomPath: "/opt/nodejs/executables/executables/phantomjs_linux-x86_64",
    script: "/opt/nodejs/executables/executables/scripts/pdf_a4_portrait.js"
   };

In my case I have added these files in the layer and provided the path, add the above configuration in options Try downloading the phantom js from here, make sure you download the correct file according to OS in your lambda environment https://phantomjs.org/download.html

Abutahir12 avatar Jul 04 '23 05:07 Abutahir12

@lahoti-piyush did you find any solution?

junaidranjha avatar Oct 04 '23 15:10 junaidranjha

So ?, Did you find any solutions? 2024 :'(

martinGM05 avatar Apr 12 '24 16:04 martinGM05

So ?, Did you find any solutions? 2024 :'(

yes, added a chromium-layer to lambda

lahoti-piyush avatar Apr 24 '24 12:04 lahoti-piyush