Search code examples
postgresqlgoogle-app-enginegoogle-cloud-platformgoogle-compute-enginegoogle-vpc

Why can't App Engine connect to Compute Engine VM instance?


I have a VM instance (e2-micro) on GCP running with postgres. I added my own external ip address to pg_hba.conf so I can connect to the database on my local machine. Next to that I have a nodeJS application which I want to connect to that database. Locally that works, the application can connect to the database on the VM instance. But when I deploy the app to GCP I get a 500 Server Error when I try to visit the page in the browser.

These are the things I already did/tried:

  • Created a Firewall rule to allow connections on my own external ip address
  • Created a VPC connector and added that connector to my app.yaml
  • Made sure everything is in the same project and region (europe-west1)

If I allow all ip addresses on my VM instance with 0.0.0.0/0 then App Engine can connect, so my guess is that I'm doing something wrong the connector? I use 10.8.0.0/28 as ip range while the internal ip address of the VM instance is 10.132.0.2, is that an issue? I tried an ip range with 10.0.0.0 but that also didn't work.


Solution

  • This answer pointed me in the right direction: https://stackoverflow.com/a/64161504/3323605.

    I needed to deploy my app with

    gcloud beta app deploy

    since the VPC connector method was on beta. Also, I tried to connect to the external IP in my app.yaml but that needed to be the internal IP ofcourse.