google-cloud-functionsservice-accountsgoogle-client

Upload data from GCS to Bigquery using service account in Cloud Functions


I have a piece of code locally that uploads data from google storage bucket into bigquery tables. It is using google cloud client library and service account as below:

client = bigquery.Client.from_service_account_json(...)

I am moving my code to Cloud Functions (python) and the runtime service account is set to App Engine Default Service Account. Do I still need to use the service account or .from_service_account_json(...) needs to be removed?


Solution

  • When running on Cloud Functions the environment is normally already initialized with the application default credentials, so you should be able to remove the service account and instead request one without explicitly specifying a service account or other credentials.

    For more on this, see the documentation on authenticating Cloud Functions for invocation.