Apollon77 / node-mbus

Nodejs mbus module
MIT License
20 stars 15 forks source link

Error when running on AWS Lambda function #90

Closed dazzlersa closed 2 years ago

dazzlersa commented 2 years ago

When testing a connection on local machine, everything works accordingly, but as soon I push to an AWS Serverless Lambda function I get the following error:

{ "errorType": "Error", "errorMessage": "/var/task/node_modules/node-mbus/build/Release/mbus.node: invalid ELF header", "code": "ERR_DLOPEN_FAILED", "stack": [ "Error: /var/task/node_modules/node-mbus/build/Release/mbus.node: invalid ELF header", " 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 bindings (/var/task/node_modules/bindings/bindings.js:112:48)", " at Object. (/var/task/node_modules/node-mbus/index.js:7:38)", " 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)" ] }

Running on NodeJs 14 locally and on Lambda.

Is there anything I can try to resolve this? TIA

Apollon77 commented 2 years ago

Honestly ... no idea ... Can you show the build part on AWS because I assume you need to do the binary build there and not upload from somewhere else for it to be compatible

dazzlersa commented 2 years ago

Thanks for the quick response bud.

Hmm. I don't Build on AWS, I just deploy from a Serverless.com YAML file and it builds and deploys to the Lambda function with the dependencies in Node_modules.

Strange this is that I have been working with Node and Serverless for over 5 years and this is the first time anything like this has happened. All other NPM packages build and deploy and work like a dream. Not sure if there is something that this specific package is doing that is breaking it... Screenshot 2022-06-20 at 08 25 55

I use my normal "sls deploy -f " to build and deploy.

Apollon77 commented 2 years ago

I have no idea ...

Maybe that helps !?

https://github.com/lovell/sharp/issues/2197 https://github.com/serverless/serverless/issues/308#issuecomment-685149964 https://stackoverflow.com/questions/29994411/invalid-elf-header-when-using-the-nodejs-ref-module-on-aws-lambda https://www.freecodecamp.org/news/escaping-lambda-function-hell-using-docker-40b187ec1e48/ ....

dazzlersa commented 2 years ago

Ok, I created a EC2 Ubuntu VM and ran the deployment from there, and it seems to have got past the previous error, but now seem to have new one.

image

if I run ldd --version ldd (Ubuntu GLIBC 2.35-0ubuntu3) 2.35 Copyright (C) 2022 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Written by Roland McGrath and Ulrich Drepper.

Do I need to downgrade my glibc version?

Apollon77 commented 2 years ago

Good question ... The module itself should not require a specific GLibC, so I wouod assume that your "build"machine has a different GLIBC then the "Lambda" one ... ?!

https://stackoverflow.com/questions/69879112/aws-lambda-how-to-fix-lib64-libm-so-6-version-glibc-2-29-not-found https://aws.amazon.com/de/premiumsupport/knowledge-center/lambda-linux-binary-package/

dazzlersa commented 2 years ago

Thanks so much for the assistance. I found that if I build it on an Ubuntu 18.04 VM, which has an older version of Glibc, build and deployed correctly. For other users, I was using macOS and it seems to be the cause when building.

Thanks again for pointing me in the right direction Apollon77

Apollon77 commented 2 years ago

yw, glad it worked out