Member-only story
Connecting Google Cloud Functions With MongoDB Atlas
Connect your serverless architecture on GCP using Cloud Functions to your MongoDB Atlas database using network peering and private clouds

Serverless functions are great, and Google Cloud Function makes them really easy to spin up. However, given the fact that they are serverless, security can pose an issue. How do I whitelist the IP of my Cloud Function in my MongoDB Atlas account if the IP is always going to be changing? We could just use 0.0.0.0
, but then we are open to attackers hammering out at our servers! We need a way to protect ourselves against these attackers while still being able to have our functions speak to each other.
In today’s article, we are going to show you how to connect your serverless Cloud Function and GCP instance to your MongoDB Atlas database.
How It Works
In a traditional non-serverless environment, a simple way to defend against attackers is to just whitelist your IP addresses. You get a server with a static IP and tell your database that IP is the only one you will accept requests from. Piece of cake.
But in serverless architecture, the requests will always be coming from different IPs. The way Cloud Functions (and other…