Praxiteles
Praxiteles

Reputation: 6020

How to bypass the Local Development Server for Google App Engine?

The Local Development Server for Google App Engine is great for testing - but we would also like to test against our databases in Google's cloud as well.

We tried setting the --host option for the Local Development Server in the hopes that we could bypass localhost - but it throws an error that it cannot bind our services on Google's x.appspot.com (i.e. where x is our project.)

How does one bypass the local development server so our Python App Engine app connects to Google Cloud SQL and Cloud DataStore in in the Cloud rather than the local versions?

Upvotes: 0

Views: 449

Answers (1)

alpeware
alpeware

Reputation: 482

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.

Upvotes: 1

Related Questions