Can't establish peering connection to Google App Engine

Hey!

I’ve set up the peering connection between MongoDB Atlas and Googles “default” VPC and the connection is labeled as “active” on both ends.

The ip range of the vpc is whitelisted in MongoDB Atlas.

But my node hosted in google-app-engine still gets timed out when accessing the MongoDB.

I use the connection url of mongodb atlas for peered connection in the form of (notice the “-pri”):

mongodb+srv://<username>:<password>@<my-cluster>-pri.rthhs.mongodb.net/<dbname>?retryWrites=true&w=majority

Which part am i missing to establich the connection? I’ve even set up a google vpc connector but the problem persists.

As soon as i delete my “allow all ip adresses” whitelist and only have the one for my peering CIDR the backend can’t connect to mongo atlas anymore.

Thanks for any help!

4 Likes

The following helped me : explored “VPC network peering” -> , clicked on “Exported routes” and chose a “destination ip addresses” for the region, where both my appengine and mongodb atlas reside.
If this does not hep you - try to review “View Database Access History” in your MongoDB Atlas project and cluster. It should give you an idea what IP addresses accesses MongoDB, while whitelist for 0.0.0.0/0 is enacted.

1 Like

I’m struggling with this as well. And I’ve managed to lock app engine out entirely, regardless of whether or not I’ve whitelisted 0.0.0.0/0. Similar to yourself, both sides according to their respective IDEs are active. I don’t suppose you figured out what the issue was since then?

It turns out that this isn’t available with Google’s app engine hosted in the standard environment. It only works with flex. It does work now though :slight_smile:

For anyone who stumbles across this post trying to find the answer, here it is:

For the App Engine Standard environment, follow this guide: cloud.google .com/community/tutorials/serverless-vpc-access-private-mongodb-atlas
Then, in your app.yaml, specify the vpc access connector you created (the region of the connector must match the region of your App Engine, either us-central1 or europe-west1)

vpc_access_connector:
  name: projects/PROJECT_ID/locations/us-central1/connectors/mongo-connector

cloud.google .com/vpc/docs/configure-serverless-vpc-access#all-other-runtimes

For the App Engine Flexible environment:
You still need the vpc network peering, but you don’t need serverless vpc access.
Follow this guide: cloud.google .com/community/tutorials/serverless-vpc-access-private-mongodb-atlas
ONLY the “Configure MongoDB Atlas VPC peering”, " Configure VPC Network Peering on Google Cloud", and “Retrieve the connection string for your cluster” sections.
Then, on the Network Access page of MongoDB, add the ip range “10.0.0.0/8” - this is the entire private ip range and includes connections from App Engine
You don’t need to change anything in app.yaml as long as you are using the default google cloud vpc network.

1 Like

For anyone who stumbles across this post trying to find the answer, here it is:

For the App Engine Standard environment

Follow this guide: Configure private access to MongoDB Atlas with Serverless VPC Access  |  Google Cloud Platform Community

Then, in your app.yaml, specify the vpc access connector you created (the region of the connector must match the region of your App Engine, either us-central1 or europe-west1)

vpc_access_connector:
  name: projects/PROJECT_ID/locations/us-central1/connectors/mongo-connector

Source: Configure Serverless VPC Access  |  Google Cloud

For the App Engine Flexible environment

You still need the vpc network peering, but you don’t need serverless vpc access.

Follow this guide: Configure private access to MongoDB Atlas with Serverless VPC Access  |  Google Cloud Platform Community
But ONLY the “Configure MongoDB Atlas VPC peering”, " Configure VPC Network Peering on Google Cloud", and “Retrieve the connection string for your cluster” sections.

Then, on the Network Access page of MongoDB, add the ip range “10.0.0.0/8” - this is the entire private ip range and includes connections from App Engine.

You don’t need to change anything in app.yaml as long as you are using the default google cloud vpc network.

Something that’s not clear in the guide is what projects are being referred to in the ’ Configure MongoDB Atlas VPC peering’ and the ’ Configure VPC Network Peering on Google Cloud’ sections.

In the Configure VPC Network Peering on Google Cloud section it says:

  1. Under Peered VPC Network , click in another project .
  2. Enter the project ID and VPC network name that were provided at the end of the previous section, in which you configured MongoDB Atlas VPC peering.

But I used the same project at the end of the previous step. If I’m not supposed to use the same project, what project am I supposed to use and where in the guide was this created?

When you enable VPC peering in the mongoDB Atlas console, you are provided with a GCP project ID and VPC name that are generated by mongoDB. You can find them under the Peering tab of the Network Access section of the mongoDB Atlas console. Please let me know if this helps!

Thanks for your quick reply @terren. That’s exactly the help i needed!