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?