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
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: https://github.com/SusriDey/pdftron-app
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
{"statusCode":500,"body":"{\"code\":\"ERR_DLOPEN_FAILED\"}"}
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.