Configuring Python Lambda Functions connection to MongoDB Atlas, Lambdas need access to Internet to reach different endpoints

Hi guys!

I have a 5 different lambda functions which need access to Internet and for this reason I didn’t setup a Custom VPC for them, so they are running in the default VPC of AWS, which grants them Internet Access.

I have a couple of doubts which are blocking my learning curve…

  • Lambdas need Internet Access in order to query different endpoints (third parties API)
  • Lambdas need to Read&Write Access to my Mongo Atlas Claster (Dedicated Configuration in the same AWS Region of the lambas)
  • I don’t want to pay for a NAT Gateway, probably my traffic is going to increase and I would like to avoid this expensive service. If you consider 5 different lambas retrieving data from the web and write and read from the cluster you undesrtand that it’s going to cost me a lot of money (0,05 USD x h + 0,05 USD x Gb)


  1. Is it ok to whitelist all the IP address provided by AWS for the Lambdas of the specific region? (the number is definity lower than :smile: . In case, which are the downsides to allow access to ALL the IPs?
  2. Granting access to the IAM Role of the functions to the clusters has nothing to do with Network Access right? By the way in terms of security is it right to state that it is better with respect the Environment Variables for user, password, url, db etc?
  3. As far as you know (probably wrong place to ask), can I use the public subnet of a CUSTOM VPC with an Internet Gateway to access the Internet from a Lambda, without using a NAT.
  4. Is it mandatory to use for this use case the VPC Peering?

According to requirements and doubts mentioned what can you advice in terms of the most suitable architecture and development logic?

Any other type of advice related to python code of the lambda will be appreciated… Having multiple lambdas reading and writing can cause a bottleneck with Mongo?

Thank you in advance, I hope that some of you can turn my night!