How to use service account in Python on GAE?

Viewed 1437

I'm wondering how to use Service Account on Google App Engine standard environment. I wrote some codes like below to access BigQuery with a proper JSON key file.

from google.cloud import bigquery
....
bigquery_client = bigquery.Client.from_service_account_json(proper_path_to_json_key)
list(bigquery_client.list_datasets())

The code works OK when I run it on a local Python interpreter but results miserably failed with the following error when it runs on local dev_appserver.py.

TransportError: ('Connection aborted.', error(13, 'Permission denied'))

When it runs on GAE, it still fails but its error message is like below.

TransportError: ('Connection broken: IncompleteRead(208 bytes read)', IncompleteRead(208 bytes read))

I think this error is caused by GAE's restriction on outbound traffic described here https://cloud.google.com/appengine/docs/standard/python/issue-requests but I have no idea how to resolve it.

What is the best way to use Service Account on GAE environment?

1 Answers
Related