Facing error ERR_DLOPEN_FAILED using PDFTron node with AWS Lambda

Product: const { PDFNet } = require(“@pdftron/pdfnet-node”);

Product Version: “@pdftron/pdfnet-node”: “^9.3.0”

Please give a brief summary of your issue:
Facing an issue using PDFTron with AWS Lambda ran locally in my machine through AWS SAM

Error: {“code”:“ERR_DLOPEN_FAILED”}
code: 'ERR_DLOPEN_FAILED’orker (/var/task/node_modules/@pdftron/pdfnet-node/lib/pdfnet.js:1161:157)

Type: AWS::Serverless::Function
CodeUri: pdftron-app/
Handler: app.lambdaHandler
Runtime: nodejs16.x

  • x86_64

Code (with demo license key):

const main = async () => {
  const doc = await PDFNet.PDFDoc.create();
  const page = await doc.pageCreate();
  doc.save("/tmp/blank.pdf", PDFNet.SDFDoc.SaveOptions.e_linearized);

      .catch(function (error) {
        console.log("Error: " + JSON.stringify(error));
      .then(function () {

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:


AWS Lambda ran locally in my machine through AWS SAM

Does this only happen in this case?
What if run the lambda normally?
What if you run one of our nodejs samples locally?

Does this only happen in this case?
Yes only when the PDF tron library is used. If I remove PDFtron library the Lambda runs fine.
What if run the lambda normally?
Lambda runs normally with Node js and core libraries like express or fs but fails with this error when PDFTron library is used
What if you run one of our nodejs samples locally?
I will try this and let you know, but I am trying to use PDFTron for AWS Lambda project build through SAM and executed locally on the docker Linux x86-64 container

I tried a sample code provided by PDFTron for AWS Lambda + Node js: -


First time I ran the code (locally through SAM docker) it threw an error saying -

License key is required for function ‘PDFNet.runWithCleanup’.\nPlease go to PDFTron Systems Inc. | Pws to obtain a demo license or Contact Sales | PDFTron to obtain a production key.",“trace”:["Error: License key is required for function ‘PDFNet.runWithCleanup’

So, I generated a demo key and put that in the code.
My code:

The code fails with the exact same error -

PS C:\AWS\SAM\pdftron-app> sam local invoke PdfUtilityFunction -e events/event.json
Invoking app.handler (nodejs16.x)
Skip pulling image and use local one: public.ecr.aws/sam/emulation-nodejs16.x:rapid-1.57.0-x86_64.

Mounting C:\AWS\SAM\pdftron-app\.aws-sam\build\PdfUtilityFunction as /var/task:ro,delegated inside runtime container
START RequestId: f4c282e5-3b1f-4112-95ee-89212765bd65 Version: $LATEST
2022-09-27T20:28:42.347Z        f4c282e5-3b1f-4112-95ee-89212765bd65    INFO    Error: {"code":"ERR_DLOPEN_FAILED"}
END RequestId: f4c282e5-3b1f-4112-95ee-89212765bd65
REPORT RequestId: f4c282e5-3b1f-4112-95ee-89212765bd65  Init Duration: 0.17 ms  Duration: 524.16 ms     Billed Duration: 525 ms Memory Size: 128 MB Max Memory Used: 128 MB

to run the code one needs to set up AWS SAM locally and run the below commands:

sam build
sam local invoke PdfUtilityFunction -e events/event.json

We have many customers using our SDK in AWS Lambda’s. So it appears that somehow in this setup the libPDFNetC.so library is either not being found at all, or its blocked somehow.

Please check the documenation for AWS SAM NodeJS on how to allow the runtime to load/read a native shared library .so file. Depending on the exact framework sometimes they need to be placed in a certain file, or registered in a config file of some sort.

Another possiblity is mixed up nodejs versions. If your lambda is Nodejs16 make sure that is how you are packaging it locally before deployment.