简体   繁体   中英

MongoDB connection from lambda using SSL doesn't work

I'm trying to connect to MongoDB-Atlas using Lambda. Locally the code runs perfectly, but using AWS Lambda I get errors related to SSL dependencies (I think...).

I want to use mongodump, so I added the latest version of mongodump binary, version r3.6.3, and I also added libssl.so.1.0.0, libsasl2.so.3, libgo.so.9 and libcrypto.so.1.0.0. All of them are in the root of the folder that I uploaded to Lambda.

This is how my relevant mongo query inside the code looks like:

mongodump -d test -u adminUser -p "notmyrealpassword" -o "/tmp/FriApr062018_1523037710445/" --authenticationDatabase admin --ssl --port 27017 -h "host0.mongodb.net,host1.mongodb.net,host2.mongodb.net"

This is how the folder looks like:

index.js  libcrypto.so.1.0.0  libgo.so.9  libsasl2.so.3  libssl.so.1.0.0  mongodump  node_modules  package.json

When I try to run it using Lambda I get this error (again, the code runs fine on a local machine):

/var/task/mongodump: /var/task/libssl.so.1.0.0: no version information available (required by /var/task/mongodump)
/var/task/mongodump: /var/task/libcrypto.so.1.0.0: no version information available (required by /var/task/mongodump)

You'll need to set the LD_LIBRARY_PATH environment variable to the directory that contains your shared object files, so mongodump knows where to find them. See this Stack Exchange answer for other ways to tell mongodump where to look for shared object files. Edit - It looks like it's able to find the shared objects, just not run them, so this probably isn't the problem.

If you have errors after mongodump is able to find them, double check that your shared object files are built in an environment compatible with the currently used Amazon Linux AMI that Lambda functions run in.

From the no version information available error and a StackOverflow answer about what that error means , it sounds like the OpenSSL libssl and libcrypto shared objects were likely built using a major.minor.patch version that's greater than what's available on the Amazon Linux AMI. As a result, you'll probably need to build them yourself so that they're compatible in the target OS. This article discusses a few reasonable ways to do that. It's for a python project, but should be adaptable to building the C modules as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM