I want a Java Appengine Managed VM application to connect to a 2nd Gen Cloud SQL Instance. There are discrepancies in the documentation - I can't figure out if this is actually supported by Google or not!
https://cloud.google.com/appengine/docs/managed-vms/java/using-cloud-sql states:
4: In the console, grant your App Engine application access to the Google Cloud SQL instance.
But I see no way of doing this. In the Cloud SQL management console, under properties of an instance, there is:
Authorized applications: None
and seemingly no way to authorize applications?
Then on this page https://cloud.google.com/sql/docs/dev-access it states:
Java App Engine Applications
Using the Cloud SQL Proxy is not supported for Java.
So you seemingly cant use the Cloud SQL proxy. The only way I have got it all working is to open the SQL port to the world, so that the managed VM instances can connect to it on its public IP address, but that is a horrific solution!
Is there an actual supported way of doing this? Anyone from Google able to answer?
April 2016 Update
We have a new Java library for connecting to Cloud SQL instances from Managed VMs and other environments: https://github.com/GoogleCloudPlatform/cloud-sql-mysql-socket-factory
It's still very new so the usual caveats apply, but we haven't found any issues in our testing.
Old answer:
I think the best option right now is to use the junixsocket library as explained in this post: https://stackoverflow.com/a/34820600
If you are using the maven-war-plugin to package your application, then adding the following two dependencies should be enough:
For Play Framework, add the following dependencies:
Configure your Play
application.conf
as follows:We hope to offer something in the future that does not require the use of junixsocket or a similar library.
We'll review/fix the documentation at https://cloud.google.com/appengine/docs/managed-vms/java/using-cloud-sql as it has some issues. Thanks for bringing it to our attention.