DEV Community

Jackson Kasi
Jackson Kasi Subscriber

Posted on

How to fix MongoDB connection Error in AWS Lambda?

Hello developers!

Hey, does Anyone face a MongoDB connection error/issue on AWS lambda?
and if you know the solution, please help me, guys!

my code works perfectly in my local system!

But when I try to post, using the API gateway endpoint, MongoDB disconnect! ( session time-out error )

Tech things 🛠️:

  • aws lambda
  • aws api gateways
  • serverless
  • node js [16.x]
  • azure cosmos DB ( MongoDB )

Image description

Image description

Top comments (1)

Collapse
 
jacksonkasi profile image
Jackson Kasi • Edited

guys, I got it!

db.js -> way 1

Image description

db.js -> way 2

Image description

index.js

Image description

credits goes to: brnaba
stackoverflow.com/users/19408037/b...

refer this!

stackoverflow.com/questions/743141...