NodeJs:Unable to connect Google Cloud SQL from Google App Engine

746 views
Skip to first unread message
Message has been deleted

Mahesh Jayashankar

unread,
Jul 19, 2019, 10:28:50 AM7/19/19
to Google App Engine

I have been working on App Engine and Cloud SQL for sometime now.


Recently I have disabled public access on my DB. Since then I am unable to connect to CloudSQL using my App Engine(Both App Engine and Cloud SQL are in same Google Cloud Project).

The only way I am able to connect is when I add the App Engine IP on CloudSQL Connections Tab. But on a new deployment the IP changes, hence adding static IP is not an ideal answer for this.

In Cloud SQL connections tab it says the following :

App Engine authorization 

All apps in this project are authorized by default. To authorize apps in other projects, follow the steps below.

Apps in this project: All authorized. Which is not true in this case.

Cloud SQL API and Cloud SQL Admin API are enabled.


connection = mysql.createConnection({
  host     : 'INSTANCE_CONNECTION_NAME',
  user     : 'db_user',
  password : 'db_password',
  database : 'db_name'
});


My app.yaml looks like below:



env_variables:
  SQL_USER: USER_NAME
  SQL_PASSWORD: PASSWORD
  SQL_DATABASE: DB_NAME
  INSTANCE_CONNECTION_NAME: INSTANCE_CONNECTION_NAME
# [END env]

# [START cloudsql_settings]
beta_settings:
  # The connection name of your instance, available by using
  # 'gcloud beta sql instances describe [INSTANCE_NAME]' or from
  # the Instance details page in the Google Cloud Platform Console.
  cloud_sql_instances: INSTANCE_CONNECTION_NAME=tcp:3306
# [END cloudsql_settings]




Expected: Get a Connection. 
Actual: getaddrinfo ENOTFOUND INSTANCE_CONNECTION_NAME INSTANCE_CONNECTION_NAME:3306

Not sure why it's taking INSTANCE_CONNECTION_NAME twice.

Harmit Rishi (Cloud Platform Support)

unread,
Jul 19, 2019, 12:46:05 PM7/19/19
to google-a...@googlegroups.com
Hello, 

Thank you for using Google Groups!

My understanding of the issue is that, you have a a Cloud SQL instance and a App Engine app living within the same project. The issue started when you removed public IP access to your Cloud SQL instance. This action hindered your app's ability to connect to the Cloud SQL instance. The only way you can now connect is by providing the App Engine IP to Cloud SQL instance via the connections tab within the SQL section of the console. 

For the purpose of clarity, would you be able to confirm your App Engine environment? My investigation into private IP's for Cloud SQL indicates that "you cannot use private IP to connect from standard environment" and that you would have to use the flexible environment. Further details of this can be found here

Also, if you are using the flexible environment, I believe it would be worthwhile to checkout the following documentation here that describes how to configure a Cloud SQL instance to use private IP. The documentation highlights requirements needed to be fulfilled on a Cloud SQL instance before using a private IP. You may see if your set-up reflects these requirements.

I hope this helps!

PS: It seems you accidentally posted your message twice. I went ahead and removed the second one on this thread. 


 
Reply all
Reply to author
Forward
Message has been deleted
0 new messages