gpt4 book ai didi

node.js - 如何使用内部 IP 从 Google Cloud Functions 连接到我的 Compute Engine MongoDB 实例?

转载 作者:IT老高 更新时间:2023-10-28 13:30:22 24 4
gpt4 key购买 nike

我的 Google Cloud Functions 与在 Compute Engine VM 实例上运行的 MongoDB 数据库完美配合,但前提是我在 Function 的 MongoClient 连接字符串中使用实例的外部 IP 地址。

如果我使用内部 IP,我希望将其用于延迟和安全性,它会在 30 秒后超时并显示:

document-create 4990695959542 DocumentCreate error: failed to connect to server [10.*.*.*:27017] on first connect [MongoError: connection 1 to 10.*.*.*:27017 timed out] document-create 4990695959542 
document-create 4990695959542 Function execution took 30025 ms, finished with status: 'timeout' document-create 4990695959542
document-create 4990695959542 Function execution started document-create 4990695959542

我的mongodb.conf如下:

# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,10.*.*.*

显然,10.*.*.* 是我的内部 Compute Engine 实例。我在 Google Cloud Function 中的 MongoClient 连接字符串中使用的 IP 相同。

如果我使用我的外部 IP 并在 mongodb.conf 中输入 0.0.0.0,它可以工作。我希望 Cloud Functions 使用他 VM 的内部 IP 连接到我的 MongoDB 计算引擎实例。

有什么帮助吗?

最佳答案

目前这是不可能的。云函数与您项目的私有(private) VPC 存在于不同的网络上,因此只有公共(public) IP 访问可用。

有一个 issue创建来请求此功能,您可以在其上添加您的请求并订阅更新。

关于node.js - 如何使用内部 IP 从 Google Cloud Functions 连接到我的 Compute Engine MongoDB 实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47913595/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com