1

I want to Import the data from my firestore to Cloud Function and do some manipulation in python language. So far I have studied the documentation but it is not much helpful Documentation.
The problem is this-->

 import firebase_admin
 from firebase_admin import credentials
 from firebase_admin import firestore
 //Use a service account
 **cred = credentials.Certificate('path/to/serviceAccount.json')**
 firebase_admin.initialize_app(cred)
 db = firestore.client()

Where will I store this file "path/to/serviceAccount.json", I can only see two files on my cloud function called Main.py and requirement.

1 Answer 1

2

The code snipped you are showing applies to using the firestore library on a local server/your machine. In that case, you have to create a JSON key file for a service account that you want to use for your requests. I recommend you familiarize yourself with service accounts first. There is also a section on keys.

However, you are running the code in a cloud function. In that case, the service account you specify as runtime service account when creating the cloud function is used for any request as default and you don't have to use a key file. So you can basically just start here and the Client will be initialized using that service account by default. Important: the service account has to have the respective permissions to use/query firestore (see my first link under service account permissions).

Sign up to request clarification or add additional context in comments.

3 Comments

Absolutely fantastic, Actually for a newbie, there is no clear documentation and I wasted so much time on searching. Can you please direct me on how can I update the data in my remote config from my cloud function? I have written Jason in my remote config. I want to push data from my cloud function to remote config.
do I have to call remote Config API in my cloud function? Please keep in mind both remote config and cloud function are at the same account.
I'm not familiar with remote config. You can have a look at the documentation and if there is a python library for using that API. However, I don't think this is in the scope of your question, so it'd be better to ask a new one.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.