简体   繁体   English

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

[英]How to connect to my Compute Engine MongoDB instance from Google Cloud Functions using the internal IP?

My Google Cloud Functions works perfectly with my MongoDB database running on a Compute Engine VM Instance, but only if I use the instance's external IP address in the Function's MongoClient connection string. 我的Google Cloud Functions与在Compute Engine VM Instance上运行的MongoDB数据库完美配合,但前提是我在Function的MongoClient连接字符串中使用实例的外部IP地址。

If I use the internal IP, that I would ideally prefer to use for latency and security, it times out after 30 second and shows: 如果我使用内部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

My mongodb.conf is as follows: 我的mongodb.conf如下:

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

Obviously, 10.*.*.* is my internal Compute Engine instance. 显然, 10.*.*.*是我的内部计算引擎实例。 The same IP I have used in my MongoClient's connection string in my Google Cloud Function. 我在Google云端功能中的MongoClient连接字符串中使用的IP相同。

If I use my external IP and in mongodb.conf I put 0.0.0.0, it works. 如果我使用我的外部IP并在mongodb.conf中我放了0.0.0.0,它可以工作。 I want Cloud Functions to connect to my MongoDB Compute Engine Instance using he VM's internal IP. 我希望云功能使用VM的内部IP连接到我的MongoDB计算引擎实例。

Any help? 有帮助吗?

Currently this is not possible. 目前这是不可能的。 Cloud functions exist on a different network than your project's private VPC, therefore only public IP access is available. 云功能存在于与项目的专用VPC不同的网络上,因此只有公共IP访问可用。

There is an issue created to request this feature, you can add your request on it and subscribe for updates. 创建一个问题来请求此功能,您可以在其上添加您的请求并订阅更新。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google Cloud Platform 使用内部 DNS 名称从 Cloud Functions 连接到 PostgreSQL 服务器 - Google Cloud Platform Connect to PostgreSQL Server from Cloud Functions Using Internal DNS Name 谷歌云函数连接到mongodb - google cloud functions connect to mongodb 使用Firebase Cloud Functions中的Google Cloud Compute Engine REST API - Use the Google Cloud Compute Engine REST API from Firebase Cloud Functions 如何将 Google App Engine NodeJS 应用程序连接到 Compute Engine 中的 MongoDB? - How do you connect Google App Engine NodeJS app to MongoDB in Compute Engine? 如何从Google Cloud Functions NodeJS连接到Google云端存储 - How to connect to Google Cloud Storage from Google Cloud Functions NodeJS 使用防火墙和 IAP 从 App Engine 或 CLoud Run 连接到 Compute Engine - Connect to Compute Engine From App Engine or CLoud Run with firewall and IAP 如何使用nodejs google-cloud / compute工具从快照在GCP上创建VM实例 - How to create a VM instance on GCP from a snapshot using the nodejs google-cloud/compute tool 如何移植谷歌计算引擎实例? - How to port forward Google Compute Engine Instance? 如何从 Cloud Functions 连接到 Google Cloud SQL (PostgreSQL)? - How to connect to Google Cloud SQL (PostgreSQL) from Cloud Functions? 谷歌计算引擎外部IP - Google compute engine external ip
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM