aws/aws-lambda-builders

Lambda application return error with libjvm.so, for a node js application

Krishman23 opened this issue · 6 comments

I have a node js application, which uses xslt4node package.
https://github.com/Krishman23/xslt-transform
After successful deployment from SAM Cli, im getting below errror.

{
    "errorType": "Error",
    "errorMessage": "libjvm.so: cannot open shared object file: No such file or directory",
    "code": "ERR_DLOPEN_FAILED",
    "stack": [
        "Error: libjvm.so: cannot open shared object file: No such file or directory",
        "    at Object.Module._extensions..node (internal/modules/cjs/loader.js:1144:18)",
        "    at Module.load (internal/modules/cjs/loader.js:950:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:790:12)",
        "    at Module.require (internal/modules/cjs/loader.js:974:19)",
        "    at require (internal/modules/cjs/helpers.js:101:18)",
        "    at Object.<anonymous> (/var/task/node_modules/java/lib/nodeJavaBridge.js:21:16)",
        "    at Module._compile (internal/modules/cjs/loader.js:1085:14)",
        "    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)",
        "    at Module.load (internal/modules/cjs/loader.js:950:32)",
        "    at Function.Module._load (internal/modules/cjs/loader.js:790:12)"
    ]
}

I did some investigation for this issue, and I found the following:

  • Your package depends on xslt4node which depends on java. You can find your package dependency here, and the xslt4node dependencies here
  • I found this issue raised before for the node-java repo here, and here. Based on the solutions mentioned in the previous posts, you need to set the JAVA_HOME environment variable.
  • Java will not be installed by default in the Lambda function, and so you need to provide it through a lambda layer function, then you can set the value of the java home environment variable. Or another solution is to create Lambda Function with Image Type.

based on the previous investigation, I do not think that this issue is related to SAM Builders.

@moelasmar thank you for your information on lambda layers. I'm new to lambda, could you please help me how we can introduce java with lambda layer ? is there any tutorials or links that refers to the solution?

sorry @Krishman23 I do not have enough info about doing that. Let me do some investigations and I will come back to you with some approach.

My feelings is using the Image type Lambda function will be easier in this case, as you can control what will exist in the running container. Do you have any preference on using the ZIP type lambda functions, or you are OK with both options ?

@Krishman23 .. were you able to find a way to include the java binaries in the lambda function layers?

Closing as there hasn't been more information provided, please reopen if there's still something you'd like the team to look into.