MongoDB 和 Google Cloud Functions VPC 对等互连? [英] MongoDB and Google Cloud Functions VPC Peering?

本文介绍了MongoDB 和 Google Cloud Functions VPC 对等互连?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在从 Google Cloud 函数访问 MongoDB Atlas 时遇到问题.它给了我关于 IP 白名单的错误,但我已将(无服务器 VPC 访问)IP 地址范围和 VPC 网络对等互连 IP 地址范围添加到 MongoDB 白名单.

我还使用谷歌云创建了 MongoDB 对等互连.

如果我允许(从任何地方访问),那么我的 mongodb 开始工作正常,否则它会给出关于 IP 白名单的错误.

当我已经添加了两个 IP 时,我不确定我还应该添加什么到 MongoDB 白名单.

有人可以帮我解决这个问题吗?一个简单的分步指南将意味着很多.(如果可能的话,图片/视频可以帮助很大)

**编辑

我使用 (Atlas GCP 项目 ID 和 Atlas VPC 名称) 创建了 (VPC 网络对等互连).而且它们都是(活动的和可用的).

之后我创建了(无服务器 VPC 访问).

并将其添加到我的(connection) 函数中,该函数将连接到 mongoDB 以获取数据.如果我将 mongoDB 设置为(允许来自任何地方),但没有它就无法工作,它可以正常工作.

之后,我将所有 3 个 IP/CIDR 块添加到 IP 白名单中.

  • MongoDB Atlas 中的 CIDR 块,如第一张图片所示.
  • 以及来自无服务器 VPC 访问的 CIDR 块.
  • 还有来自 VPC Network 的 CIDR Blcok,就像上面所有的一样.

但我仍然很困惑,当我运行这个函数时,它仍然给我关于 IP 白名单的错误,并且只有当我允许来自 mongoDB 中任何地方的流量时才有效.

不知道自己做对了什么,做错了什么.由于互联网上没有任何视频可以实现这一目标.

我什至尝试了这篇文章,但仍然没有任何效果.

解决方案

如果您知道需要将特定 IP 列入白名单:

  • 将所有 IP 列入白名单.
  • 连接成功.
  • 下载服务器日志.
  • 找出连接来自哪个 IP.
  • 将该 IP 列入白名单.

验证此 IP 在您预期的范围内等.

如果您知道不需要将特定 IP 列入白名单:

  • 参考 Atlas 文档,其中说明了 VPC 对等互连的工作原理(中等帖子不能替代官方文档).

如果您不知道是否需要将特定 IP 列入候补名单:

  • 按照第一个程序并将您的 IP 列入白名单.
  • 然后查找说明正确用法的官方文档.

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.

解决方案

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.

这篇关于MongoDB 和 Google Cloud Functions VPC 对等互连?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆