0
votes

I am using Java 8, so as to connect with Google Cloud SQL from Google Standard App Engine. Tried sample available at below link too so as to test connection https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/cloud-sql/mysql/servlet

Issues I am facing:

  1. If Connection name available at https://github.com/GoogleCloudPlatform/java-docs-samples/blob/master/cloud-sql/mysql/servlet/src/main/webapp/WEB-INF/appengine-web.xml, is incorrect I am able to get HTTP code 500, and error log at error console of google as instance name is wrong
  2. When I am using correct instance name, there is no error in error console, but connection is not working

I have following components available at my Google cloud:

  1. Java 8 based Standard App Engine Application
  2. Serverless VPC access under VPC network
  3. Cloud SQL 5.7 with Private IP

Thanks

1

1 Answers

1
votes

As described in the official doc, you have 2 alternatives to connect to Cloud SQL from App Engine Standard environment :

  1. Cloud SQL in public IP = use Cloud SQL Proxy with INSTANCE_CONNECTION_NAME

  2. Cloud SQL in private IP = Connect using your instance's private IP and port 3306, via Servless VPC configuration.

It means in your case, if your Cloud SQL instance has only private IP, you have to connect to it directly via Serverless VPC.

Note that your App Engine standard application need a correct setup to be able to send traffic via Serverless VPC connector, with at least these 2 main points :

  1. Serverless VPC Access connector need to be in the same project and region than the GAE application which uses it.

  2. GAE app needs to be configured with VPC connector in the appengine-web.xml file for Java8 runtime as below:

<vpc-access-connector>
  <name>projects/PROJECT_ID/locations/REGION/connectors/CONNECTOR_NAME</name>
</vpc-access-connector>

More details on how to configure Serverless VPC connector with GAE standard Java8 runtime.