Database Triggered Cloud Functions across multiple Firebase projects - firebase

Is it possible to trigger a cloud function on a database instance of another firebase project? From what I've read so far, the documents mention passing an instance name in the function but this would be an instance in the same project.

It's not possible. Both functions and database shards must be contained within a single project.

Related

Where to store Google Service Account Key while using Google Firebase Functions

Using Google Firebase Functions as a backend of the small application.
Functions are accessing to the Firestore and Realtime database, therefore they need service account credentials file.
On the other hand, I'm trying to automate the deployment of the functions using Github Actions.
Currently I places the credentials file inside the repository. I know that it's not secure.
What is the proper way of storing service account credentials file in this case?
Firebase projects, are, in effect, Google Cloud Platform projects.
More specifically, when you create a Firebase project, an associated Google Cloud Platform project is created for it.
Therefore the process for storing credentials is the same as in Cloud Platform, which is to say in a file, somewhere relatively safe.
This file should be accessible to your Function if it is required, and should either have its path specified as part of an environment variable or explicitly declared in code.
You are already storing it the proper way, because the improper way would be to insert the contents of the JSON file directly into code.
To prevent others from seeing the contents of the JSON file, simply set the respository as private.

firebase documentation terminology

What do we mean by secondary Firebase App? for instance, it is mentioned here in this documentation - https://firebase.flutter.dev/docs/auth/usage
Use multiple projects in your application
Sometimes you need to access
different projects using the same APIs - for example, accessing
multiple database instances. In most cases there is a central Firebase
application object that manages the configuration for all the Firebase
APIs. This object is initialized as part of your normal setup.
However, when you want to access multiple projects from a single
application, you’ll need a distinct Firebase application object to
reference each one individually. It’s up to you to initialize these
other instances.
In both cases, you need to first create a Firebase options object to
hold the configuration data for the Firebase application
you can read more here

Cloud Functions: Store Simple Shared Value Across Instances without Database/VPC?

Writing a firebase/google cloud function, and need to store an environment value for use across multiple function calls. That value expires and needs to be re-fetched on occasion and updated in production.
I'm looking for a lightweight option for that. Seems all the advice I can find is that you need to spin up a VPC and create a dedicated Redis instance... or you need to create a cloud database and store it there... I just need to save a simple string, and it seems like an awful lot of infrastructure to do that.
One would think environment variables would work, but you can only set on the command line and they are only refreshed on deploy...
To store environment data, you can use the firebase
functions:config:set command.
To get environment data, you can use the functions.config() function.
See https://firebase.google.com/docs/functions/config-env.
So, is there a way to update/set a value in my code? I cannot rely on the command line to update it as it expires, like a cron to update and redeploy.
In Google Apps Script, for example, I'd just use the 'cache' helper service and store the value for a few hours. Any equivalent cache available to cloud functions without resorting to storing on GCS or in a database (it's a single, simple token string...)? Thanks.
Cloud Functions does not offer any form of shared environment variables between functions. You will need to look to an external source such as Cloud Secrets Manager, Cloud Storage or one of the databases. I use both Cloud Storage and Datastore for this feature. I am now looking into Cloud Secrets Manager as my software usually has secrets as well.

Connect firebase function from realtime DB to Spanner

I have an app with tens of thousands of users where every second we are capturing data (location data). For analysis we are trying to allow this data to be queryable to generate reports for the user.
The idea is to pass the data in the Realtime database to Spanner so that I can query the data in SQL format and generate reports based on that.
I want to be able to do this from my trigger everytime that I update the realtime database.
So data follows this flow:
iOS / Android location data -> writes Firebase Realtime DB -> Function trigger based on write event -> Add to Spanner
Is this possible and if so how do you suggest it being done?
I am already using firebase functions to trigger notifications and keep database consistency, but not sure how to connect to spanner. The documentation that I have found is all about Cloud functions and when I do
const Spanner = require('#google-cloud/spanner');
I get the "Error: Error parsing triggers: Cannot find module '#google-cloud/spanner'"
My first limitation is: Are firebase functions limited to firebase itself or can I integrate with other cloud tools such as spanner?
Thanks,
Ricardo
I don't have experience with Realtime Database, PubSub and Functions, but I'm also interested :)
I imagine 2 steps: [1] Firestore triggers can publish message to PubSub, and [2] Functions can subscribe and handle PubSub events which interact with Spanner.
[1] How to publish message in Google Pub/Sub from Firebase Cloud Function?
[2] Google Cloud Pub/Sub Triggers  |  Cloud Functions
[2] Using Cloud Spanner with Cloud Functions  |  Cloud Functions
The error means you haven't (correctly) installed the Cloud Spanner client library. To fix this, in your functions folder run:
npm install #google-cloud/spanner
Unless you actually need the data in RTDB, you can avoid that step entirely and call a Cloud Function directly: See HTTP Functions.
There is a handy 'How-to Guide' on writing a Cloud Function for interacting with Cloud Spanner in the documentation, just modify it for put instead of get: See Using Cloud Spanner with Cloud Functions

What's the best way to store static data in firebase

I'm writing firebase android app in android studio. I have almost 2000 geo locations and I want them to be marked on map all the time. Firebase databse isn't good idea to store such data because this is static data. So firebase storage, hosting, just some list in code or something different would be the best way?
Thanks in advance
For static data, you could use list and append all the geo locations with push() method. The push() method generates a unique key every time a new child is added to the specified Firebase reference.
By using these auto-generated keys for each new element in the list, several clients can add children to the same location at the same time without write conflicts. The unique key generated by push() is based on a timestamp, so list items are automatically ordered chronologically.
For static data that you create yourself, I'd use Firebase Hosting. It gives you a simple way to update the data with firebase deploy, and comes with a built-in CDN.
For unstructured data that your users create, use Cloud Storage for Firebase.
For structured data that your users create, use Cloud Firestore or the Realtime Database.
Also see: Firebase : Differences between realtime database and file storage

Resources