简体   繁体   中英

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.

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:

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:

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

Obviously, 10.*.*.* is my internal Compute Engine instance. The same IP I have used in my MongoClient's connection string in my Google Cloud Function.

If I use my external IP and in mongodb.conf I put 0.0.0.0, it works. I want Cloud Functions to connect to my MongoDB Compute Engine Instance using he VM's internal IP.

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.

There is an issue created to request this feature, you can add your request on it and subscribe for updates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM