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.