I'm simply trying to use Serverless and Lambda to make get and post requests to my Atlas cluster. I've followed all the tutorials below which are very similar:
https://hackernoon.com/building-a-serverless-rest-api-with-node-js-and-mongodb-2e0ed0638f47
https://dev.to/adnanrahic/a-crash-course-on-serverless-apis-with-express-and-mongodb-193k
https://dev.to/saigowthamr/build-and-deploy-a-rest-api--using-serverless-express-and-nodejs-3331
Using Insomnia or Postman I can make get and post requests to a locally hosted database but not to an Atlas cluster. The requests always result in 502 Bad Gateway with JSON message of "internal server error". I've tried switch up the cluster host from AWS to Azure and that didn't help. In regard to the various drivers I've tried every variety of connection string. I've whitelisted all ips so access is not an issue. Please help.
I deleted the cluster, project, organization, and users in my Atlas account and started over. I didn't manually create a new user through the Network Access tab but rather created a user with the prompt you get when creating a Cluster. I noticed there was a note regarding special characters when making a connection:
When entering your password, make sure that any special characters are URL encoded.
My previous password used an @ symbol which may have been causing problems. So be careful when using email addresses as user names. I assigned 0.0.0.0/0 to the user as usual. I don't think it matters but I only have one user and I added a comment to that user as well. Now I can make a connection using the 2.2.12 or later Node.js driver connection string. I hope this helps someone.