Va5ili5
Va5ili5

Reputation: 798

Google Cloud Function cannot connect to Redis

We have a Google Cloud Function that tries to connect to a Redis server that sits on a Compute Engine instance. The Compute Engine Redis port is open and can connect to the Redis server from our local machines. Nonetheless, when the Cloud Function tries to do so, it gets the following error:

Redis connection to 35.xxx.xx.xx:6379 failed - connect ETIMEDOUT 35.xxx.xx.xx:6379 at Object.exports._errnoException (util.js:1020:11) at exports._exceptionWithHostPort (util.js:1043:20) at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1105:14) code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect', address: '35.xxx.xx.xx', port: 6379 }

We are using the redis npm package (Redis Node Client) to connect which again works from our local machines.

We pass the IP of the EC server to the host value and the authentication secret to the password value. Again this seems to work locally.

Any ideas?

Upvotes: 4

Views: 3770

Answers (2)

dotNet Decoder
dotNet Decoder

Reputation: 531

GCP has released beta version of "Serverless VPC access" to connect Compute Engine VMs from a Cloud Function using internal IPs. Follow the tutorials here

Upvotes: 1

Va5ili5
Va5ili5

Reputation: 798

After all, it was indeed a firewall issue. We didn't have the correct service account setup.

One needs to visit the firewall rules config page and add the appropriate Source Filter (or Second source filter) to type Service Account and add the service account of the Cloud Functions.

Upvotes: 6

Related Questions