Can’t Connect from GCP AppEngine to GCP Cloud SQL

google-app-enginegoogle-cloud-platformgoogle-cloud-sql

I have a simple Java servlet app, deployed to the GCP AppEngine.
Under the same GCP, I have created a MySQL instance of GCP Cloud SQL.

I would like to save the value on MySQL server when someone makes an HTTP Post request. However, my Java App cannot connect to GCP Cloud SQL.

On the Cloud SQL page, it says All apps in this project. All authorized.
However, my Java app can't connect even though they are under the same GCP Project.

When I add all the networks, it works correctly. However I don't want to do this:

ss from gcp console

What could be the reason that I can't connect to Cloud SQL from the App Engine?
Is there some configuration that I need to do?

Best Answer

You shouldn't whitelist 0.0.0.0/0 - this allows any IP address to attempt to connect to your instance, and will be

I would suggest using the Cloud SQL JDBC Socket Factory. The Socket Factory uses service account credentials to authenticate connections to your instance.

You can also check these instructions on the Connecting from App Engine page to make sure you have enabled the correct API and given the service account the correct permissions.

Related Topic