I am getting higher latency when invoking Cloud Run using Firebase as described in the below tutorial.
https://firebase.google.com/docs/hosting/cloud-run
Response time:
Firebase hosting invoking Cloud Run: 785ms(relatively very high as compared to native Cloud Run response time)
Native Cloud Run: 170ms
Note: We are using the same region/location for Firebase and Cloud Run: asia-northeast1
What you expected to happen:
Latencies from both should be comparable or the same.
1- Call any URL from Firebase hosting invoking Cloud Run(refer attached screenshot)
2- Call any URL from Native Cloud Run(refer attached screenshot)
Related
Today i ran into a problem with my Firebase Cloud Function that generates images sizes when new images are being uploaded to the Firebase Storage. This problem causes my quota to exceed after a couple uploads and when the quota exceeds the limit i am not able to use firebase anymore. Now i am trying to run this Cloud Function locally so that my quota will not exceed.
I tried running the emulator in my terminal with this command: firebase emulators:start
This initializes all my Cloud Functions except my Firebase Auth and Firebase Storage functions. The firebase docs say the emulator only supports:
HTTPS functions
Callable functions
Cloud Firestore functions
Is there a way/work around so i can run my Firebase Storage and Firebase Auth functions locally?
From the emulator, no. As you've seen, they're just not supported.
Look into invoking functions using the functions shell, or unit testing your functions with the functions-test module.
I'm building a firebase API with cloud functions and want to reach my production Database for local testing.
My problem :
When I launch my two firebase emulator (functions and firestore) with
firebase emulators:start
1- My custom API endpoints run on http://localhost:5001 (this works)
2- My triggers reaches a local dababase on http://localhost:8080 whereas I didn't set FIRESTORE_EMULATOR_HOST=localhost:8080 (I want to reach my production database)
OR
When I launch only my "functions emulator" with
firebase emulators:start --only function
...but my triggers are not reached, probably because of this warning
i functions[userOnCreate]: function ignored because the firestore emulator does not exist or is not running.
On the other side I'm building a reactjs App also with firebase running on localhost:3000
I call my local API from this app with firebase SDK. To reach my emulator, I add the line :
firebase.functions.useFunctionsEmulator('http://localhost:5001');
The local emulators don't work with actual cloud-hosted instances of databases. Everything must be local.
You are always free to file a feature request.
you have to use firebase serve instead for firebase emulators:start
From Firebase DOCS:
Run functions locally
The Firebase CLI includes a Cloud Functions emulator which can emulate the following function types:
HTTPS functions
Callable functions
Cloud Firestore functions
You can run functions locally to test them before deploying to production.
QUESTION
Is there a way to run cloud functions for Firebase Storage (ex: triggered by file upload) locally or do I need to actually deploy them for testing?
firebaser here
Update: the Firebase Emulator Suite now also supports Cloud Storage. This includes uploads to emulated Cloud Storage triggering emulated Cloud Functions.
See the documentation for full details.
Storage has been implemented in firebase tools 9.11.0. I just took it for a test run, and I found that functions running in the emulator are, indeed, triggered by uploads to the emulated storage.
https://github.com/firebase/firebase-tools/issues/1738#issuecomment-843256335
I know how to send messages from Firebase cloud messaging portal to an android device. But my server runs on Google Cloud, I do gcloud app deploy from my local machine and the app logic gets deployed on Google Cloud. Now, I want to send notifications, based on the data stored as Entities in GCP Datastore, to an Android App.
Notification messages can be sent from Firestore-Cloud Messaging portal to an Android device, if I could harness this Firestore Cloud Messaging API in my GCP logic, then my problem will be solved.
I'm trying to look for any examples or POC's.
you can use Cloud Functions to add such custom functionality...
for example: https://android.jlelse.eu/serverless-notifications-with-cloud-functions-for-firebase-685d7c327cd4
and there are Cloud Datastore Callbacks, which can be used as event triggers. most relevant for Cloud Functions might be the Google Cloud Datastore Node.js Client - in order to connect to the Datastore. here's one of my examples, it is written in AppScript (similar to Node.js), which also connects to a Cloud Datastore, with the service account JSON loaded from Google Drive.
however, in this case the Datastore would need to subsequently trigger an HTTP Trigger or Pub/Sub Trigger and the code behind that trigger could get more data from the Datastore or directly send the Firebase notification.
in Cloud Function there are just triggers for Cloud Storage, while the Pub/Sub (publish/subscribe) triggers can be used for just anything. The Datastore would need to publish whatever event (add/edit/update/delete) - while a Cloud Functions script would need to subscribe these events.
using Firebase as backend might be less effort, because data-change events/triggers are being supported out-of-the-box, without any HTTP interaction or Pub/Sub communication involved.
TL;DR:
Does my firebase project incur charges/use up quota by running firebase functions locally using $firebase serve --only functions?
Details:
I have a collection in my firestore database called locations with thousands of documents that include location data such as address and postCode. I want to add some geolocation data to each document using an external api service (Open Postcode Geo API). I've written an HTTP-triggered firebase function, triggered by hitting the endpoint /api/geocodeLocations. This cloud function will run through each document in the locations collection and use the postCode data to make an api call to Open Postcode Geo which will respond with the geolocation data (along with other data). It will then get the data it needs from the response and write it to the document in firestore.
I am aware that if I deploy this function and call it by hitting https://my-project/api/geocodeLocations, I will start racking up my quotas and maybe incur charges for the amount of external requests that it's making (and more than likely time out...). However, if I run $firebase serve --only functions locally on my dev machine to emulate functions and then hit the url http://localhost:5000/my-project/us-central1/app/api/geocodeLocations, will I still rack up quotas for external requests?
I don't think I will, as the requests are between my local machine and the external api, but I can't find any firebase documentation on quotas when running locally.
Thanks in advance!
Running functions locally in any way doesn't cost anything in terms of billing or quota for the Cloud Functions product.
If you read data out of Firestore or Realtime Database in a function running locally, you will still be billed for that access, but it won't be in relation to Cloud Functions billing or quotas.