Connect to MongoDB atlas with AWS Lambda error

Hello everyone,
When I’m trying to connect to my atlas from AWS Lambda with PyMongo

connect(**credentials)

I’m getting this error:

“errorMessage”: "The “dnspython” module must be installed to use mongodb+srv:// URIs.

I tried to add to the requirements.txt file pymong[srv] and got the same error, and when I changed pymongo to [srv] I got “No module pymongo”.
I also tried to add [srv,tls] and got the same error.
When I’m trying to add to the app.py:

os.system(‘pip install pymongo’)

I’m getting

“errorMessage”: “[Errno 30] Read-only file system: ‘/home/sbx_user1051’”]

I have no idea what else I can do, does anyone have any idea?

1 Like

Hi @Orel_Levi welcome to the community!

If I understand correctly, you’re having issues using/installing Pymongo from AWS Lambda. Is this correct?

For using external dependency in Lambda, please have a look at external dependencies in Lambda functions. In short, you’ll need to package the script and dependencies in a zip file that you’ll need to upload to Lambda.

Also, I believe you’re using Atlas (due to the mention of the srv protocol in your post). Please note that due to the nature of Lambda, you’ll need special care in connecting Atlas (or any other database service, I believe). The documentation for managing connection to MongoDB in a Lambda function may be useful for you.

Best regards
Kevin