Kentaro
Kentaro

Reputation: 145

Django on Google App Engine connection to Cloud SQL, cannot connect

I have a Django app deployed on App Engine.

Inside the same project, I've set up a MySQL instance set up with a Private IP.

Side Note: I've been using this DB to do local development, and can connect to it via my laptop as I whitelisted the IP address, so I know I can at least connect to it.

Per the instructions on the instruction guide found here: https://cloud.google.com/sql/docs/mysql/connect-app-engine-standard

I have done the following:

  1. Set up my Cloud SQL Instance with a Private IP
  2. Set up a Serverless VPC Access connector (this is where I think I'm going wrong) with IP Address Range 10.8.0.0/20
  3. Set my DATABASES dictionary in settings.py to try to connect to each of the following IP addresses with all failing: The private IP (x.x.x.x) listed on the SQL server page, on port 3306. 127.0.0.1 as per the instructions on the google web page. I tried 10.174.0.0 because that's listed as the "Internal IP Range" in the VPC networks area. And finally, out of desperation, 10.8.0.0, because that's the example given as the textbox hint.
  4. In the Cloud SQL GUI, I set the "Network" to Default.

All failed, but in different ways.

The Private IP at least gave me a Django Debug error saying "x.x.x.x could not be connected to via MySQL."

The 127.0.0.1 gave me the same error.

10.8.0.0 gave me a "502 Bad Gateway (nginx) error.

I don't know what I'm doing wrong. The instructions aren't clear to me. This line is especially confusing:

"Create a Serverless VPC Access connector in the same VPC network as your Cloud SQL instance."

How do I know/find out which VPC network my Cloud SQL instance is in? I go to VPC networks and I see the "internal IP ranges" column, and the region where I've deployed the Cloud SQL resource is something like 10.171.0.0. Is that the VPC network?

Upvotes: 0

Views: 685

Answers (1)

I just tested the documentation you are working with, and I did not get any error message with a Private IP.

Something important that you should have in mind are the requirements for Private IP and, optionally, you can specify an allocated IP range for your instances to use for connections, expand the “show allocated IP range” option, and select an IP range from the drop-down menu.

To review which VPC network your Cloud SQL instance is in, you need to select your VPC Network and then review the column for instances.

Upvotes: 1

Related Questions