'Firestore emulator with anonymous credentials

I am trying to get Firestore working in emulator-mode with Python on my local Linux PC. Is it possible to use anonymous credentials for this so I don't have to create new credentials?

I have tried two methods of getting access to the Firestore database from within a Python Notebook, after having run firebase emulators:start from the command-line:

First method:

from firebase_admin import credentials, firestore, initialize_app

project_id = 'my_project_id'

cred = credentials.ApplicationDefault()
initialize_app(cred, {'projectId': project_id})
db = firestore.client()

This raises the following exception:

DefaultCredentialsError: Could not automatically determine credentials. Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application. For more information, please see https://cloud.google.com/docs/authentication/getting-started

Second method:

from google.auth.credentials import AnonymousCredentials
from google.cloud.firestore import Client

cred = AnonymousCredentials()

db = Client(project=project_id, credentials=cred)

This works, but then I try and access a document from the database that I have manually inserted into the database using the web-interface, using the following Python code:

doc = db.collection('my_collection').document('my_doc_id').get()

And then I get the following error, which perhaps indicates that the anonymous credentials don't work:

PermissionDenied: 403 Missing or insufficient permissions.

Thoughts

It is a surprisingly complicated system and although I have read numerous doc-pages, watched tutorial videos, etc., there seems to be an endless labyrinth of configurations that need to be setup in order for it to work. It would be nice if I could get Firestore working on my local PC with minimal effort, to see if the database would work for my application.

Thanks!



Solution 1:[1]

AWS CDK's main purpose is to provision infrastructure. Managing the data stored on those infrastructure is an entirely different story.

Deploying Updates to Static Site
If the goal of this rename operation is for deployment purposes, I would suggest to just use AWS CLI, this makes release process much simpler with less risk as the underlying infrastructure is not at risk of unintentional modifications / bugs in the updates made on the infrastructure's CDK templates.

This option makes mounting on a CI/CD pipeline much more simpler too!

Managing application data If the goal of this rename is to manage application data, I would suggest using AWS SDK for your language of choice.

Layering automation is a subtle best practice! Using these automation tools for the right goal / use-cases can empower us to deliver changes quicker to customers!

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Allan Chua