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 whitelist the App Engine IP on CloudSQL. 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.
Have googled the issues and followed the steps in document and other stackoverflow questions :
1) Cannot access Google Cloud SQL database from my App Engine
2) Node JS Mysql PROTOCOL ENQUEUE AFTER FATAL ERROR
3) "PROTOCOL_ENQUEUE_AFTER_FATAL_ERROR" in Node-MySqL
4) Error: Cannot enqueue Query after fatal error in mysql node
5) not able to connect google cloud sql from google app engine
All of these haven't helped a lot.
connection = mysql.createConnection({ host : 'INSTANCE_CONNECTION_NAME', user : 'db_user', password : 'db_password', database : 'db_name' });
Expected: Get a Connection.
Actual: getaddrinfo ENOTFOUND INSTANCE_CONNECTION_NAME INSTANCE_CONNECTION_NAME:3306
Not sure why it's taking INSTANCE_CONNECTION_NAME
twice.