Lambda function connection with mongodb atlas

Hi, I m trying to make connect lambda function written in python to mongodb atlas without any ec2 instance.It is a serverless service. But my connection closes as soon as I get the pymongo cursor.Attached is a screenshot. I do not know why my connection is closing without data is being read. It raises and exception called connection closed. Can anyone help?