Cloud Datastore
There is now a client google-cloud-python that allows you to directly access the datastore assuming the client has the correct credentials.
The easiest way to try this out is in a Cloud Shell -
$ sudo pip install --upgrade google-cloud
$ python
>>> from google.cloud import datastore
>>> client = datastore.Client(project='YOUR-PROJECT-ID')
>>> query = client.query(kind='YOUR-ENTITY')
>>> for result in query.fetch():
>>> print(result)
You can find more information on authentication in the docs.
Cloud SQL
You can connect to a Cloud SQL instance through the following ways:
- IP address (with and without SSL)
- Cloud SQL Proxy (binary or Docker image)
- MySQL Socket Library (Java only)
- Go Proxy Library (Go only)
- Cloud Shell (uses temporary IP whitelisting)
I'd recommend connecting through the Cloud SQL Proxy.
Alternative for testing
I believe it's also worth asking yourself what you are trying to test and whether you can avoid connecting to the prod DB directly. I'd recommend setting up a staging environment instead where you can import a subset of prod data on a regular basis through a script, properly anonymizing sensitive user data and running your E2E tests against that environment to avoid any potential negative side effects on your production system.