Deploying Python Script as Cloud Function with access to Cloud Firestore

Viewed 43

I'm trying to deploy a Python project as a Google Cloud Function.

I found this Tutorial.

Where basically you just have to write functions from inside the Cloud Functions section of the Google Cloud Dashboard.

I just have a question as I have been working on my local machine I had to download a serviceAccountKey.json file from my Firestore Project Settings, in order to access my Firebase Firestore.

serviceAccount Json File

In order to access the Firestore I add this code on my Script:

cred = credentials.Certificate("serviceAccountKey.json")

How can I use my script to access that file when I write the code in the Cloud Function of the Google Dashboard or is there another way to do the deployment of that script so it can still work or have access from my script to Cloud Firestore?

Kind Regards

1 Answers

Check the docs. The SDK can also be initialized with no parameters. In this case, the SDK uses Google Application Default Credentials. Because default credentials lookup is fully automated in Google environments, with no need to supply environment variables or other configuration, this way of initializing the SDK is strongly recommended for applications running on Compute Engine, Kubernetes Engine, App Engine, and Cloud Functions.

To optionally specify initialization options for services such as Realtime Database, Cloud Storage, or Cloud Functions, use the FIREBASE_CONFIG environment variable.

default_app = firebase_admin.initialize_app()
Related