MongoDB and Google Cloud Functions VPC Peering?

ぐ巨炮叔叔 提交于 2021-02-13 17:33:21

问题


I've having issues accessing MongoDB Atlas from Google Cloud functions. It is giving me error regarding IP Whitelisting but I've added both (Serverless VPC Access) IP address range and VPC Network Peering IP address range to MongoDB whitelist.

I've also created MongoDB peering with google cloud.

If I allow (access from anywhere) then my mongodb starts working fine, otherwise it gives error regarding IP whitelisting.

I'm not sure what else I should add to MongoDB whitelist when I've added both IP's already.

Can anyone help me regarding this? A simple step by step guide will mean a lot. (images/video can help big if possible)

**Edit

I took (Atlas GCP Project ID & Atlas VPC Name) to create (VPC Network Peering). And they both are (Active & Available).

And after that I created (Serverless VPC Access).

And added it to my function inside (connection), a function that will connect to mongoDB to get data. It works fine if I set mongoDB to (allow from everywhere) but do not work without it.

And after that I added all 3 IP's/CIDR blocks to the IP Whitelist.

  • The CIDR Block from MongoDB Atlas as in 1st image.
  • And CIDR Block from Serverless VPC Access.
  • And CIDR Blcok from VPC Network as well just like all above.

But I've still confused that when I run this function it still gives me error about IP Whitelist and only works if I allow traffic from everywhere in mongoDB.

Don't know what I'm doing right and what I'm doing wrong. As there aren't any videos available on internet to achieve this.

I even tried this article but still nothing works out.

https://medium.com/better-programming/connecting-google-cloud-functions-with-mongodb-atlas-499a0a82ccf3

This is the error I'm getting.


回答1:


If you know you need to whitelist specific IPs:

  • Whitelist all IPs.
  • Connect successfully.
  • Download server log.
  • Figure out which IP the connection came from.
  • Whitelist that IP.

Verify this IP is in your expected range, etc.

If you know you don't need to whitelist specific IPs:

  • Reference Atlas documentation that says so and explains how VPC peering is supposed to work (medium posts are not a substitute for official documentation).

If you don't know whether specific IPs need to be waitlisted:

  • Follow the first procedure and whitelist your IPs.
  • Then look for official documentation stating what the proper usage would be.


来源:https://stackoverflow.com/questions/64945739/mongodb-and-google-cloud-functions-vpc-peering

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!