Search code examples
mongodbamazon-web-servicesaws-lambdapymongoaws-vpc-peering

Unable to delete documents when AWS lambda is in VPC (pymongo)


I am using MongoDB Atlas and AWS Lambda. My backend lambdas are written in python and i am using pymongo[aws] to connect to my cluster.

I have setup peering to allow connectivity only from inside my VPC.

When i run a query col.find, col.update_one, ... they are working fine, but when i call delete_one it times out.

Inside the VPC the lambda has no internet access but i didn't think it would be required for deletion...

Unless i am completely wrong, please why delete_one times out in my configuration ?

EDIT :

The AWS lambda contains 5 queries including update_one, find and delete_one.

Only the delete_one from this same lambda is timing out. Also, if i simply remove the lambda from the VPC, the delete_one is working again.

I add the link to my case in MongoDB community which was linked to connectivity using AWS credentials, but i have fixed this and i am asking at the end the issue with the delete_one.


Solution

  • It was a silly mistake, i have not seen a nested method that was waiting for a response from another service on the internet, the delete_one is completely out of cause. I have spotted this by trying the delete_one on a minimalist Lambda function that was working.

    To fix the issue, i have setup a Nat Gateway to route my traffic on the internet from my private VPC by using some public subnets.

    The communication between my AWS Lambda and my MongoDB cluster atlas is still in peering and on private subnets.