I have a lambda function that is connecting to a remote MongoDB on EC2 using typescript. I am able to connect to the database locally, when in lambda it gives me a ELF error. Upon my research I see that this is more so due to mismatched binaries of npm packages when built. eg(linux/mac/windows) etc.
the error string in
Stack: ERROR:/var/task/node_modules/snappy/build/Release/binding.node:Invalid ELF Header.
Yet its only this npm package, mongoose or mongoDB native package when installed it give this error.
my ec2 instance is running ubuntu server, and my lambda is on node, I am using serverless template.yml to upload/package the code to lambda.
what could be causing this error? is it lambda? or is my ec2 OS causing this error.
I do not think the Linux OS on ec2 would cause this issue, since it is only the host of the DB and not causing the mismatch of environments issue. (correct me if I am wrong).
My connection string and code is as follows.
import mongoose from 'mongoose';
mongoose.connect('mongodb://IPADDRESS:<PORT>/DB');
npm package is:
"mongoose": "^5.12.12",
If I remove mongo connection string/packages it works. This error is both with mongodb native and mongoose packages. Once I remove them the error goes away and everything works correctly.
What is the correct way to debug / solve this. I am guessing a lot of people use mongoose with lambda, so I am unsure what is causing this error.