Firebase Cloud Functions pricing for Admin SDK - firebase

Is 125k invocations per month for Firebase cloud functions applies to admin-sdk used on custom server? How price of cloud functions is calculated if used with admin sdk on self hosted server?

The 125k invocations per month you are referring to is talking about how many times a Cloud Function is executed/triggered (the term used by Firebase here is invoked). Use of the admin SDK on your own hardware/third-party server doesn't make use of Cloud Functions and is unrelated to the invocation limits.
Let's say you set up a HTTPS Cloud Function called date. Each time a user visits https://us-central1-<project-id>.cloudfunctions.net/date, this would count as 1 invocation of that Cloud Function (ignoring response caching/use of a CDN).
Another example is listening for new data in Cloud Firestore that you can call createUser. Each time a new users/someUserID document is created, the createUser function would be invoked.
For such trivial use cases, you aren't likely to hit the 125k limit. But if you have Cloud Functions that deal with frequently modified data or rapidly triggered pub/sub topics, you can quickly approach these limits if care is not taken.
One example of this is if you set up a RTDB Cloud Function that was incorrectly listening to any data under /posts. Every time a user (or server) changed any data under /posts, the function would be invoked. If your cloud function updated /posts/count everytime it was called, the cloud function would retrigger itself leading to an infinite loop.

Is 125k invocations per month for Firebase cloud functions applies to admin-sdk used on custom server?
Cloud Functions billing is not at all related to whatever billing is incurred by the Admin SDK. If you use the Admin SDK, you will be billed according to the products it uses, in addition to whatever billing might happen for Cloud Functions.
How price of cloud functions is calculated if used with admin sdk on self hosted server?
It's not possible to self-host Cloud Functions. Cloud Functions only runs within Google Cloud infrastructure.
If you use the Admin SDK on your own host, outside of Cloud Functions or any Google Cloud hosting, it does not change the billing compared to the same usage in Cloud Functions.
If you want to know what the cost is for using the Admin SDK, you should understand which product you are accessing with that SDK, and look up its own pricing. The Admin SDK itself does not bill - it is the usage of the underlying Firebase or Cloud product that incurs billing.

Related

Firebase billing turn off puppeteer cloud functions

My question consists two parts
What if I turn off Firebase billing and switch to spark plan will all cloud functions will be deleted?
Can I turn off billing using cloud functions and puppeteer to prevent myself from attack?
According to the documentation, your data is not getting deleted but your project loses access to paid features.
There is an example of how to stop billing using Cloud Functions described in the automated cost control responses guide.

Firebase and GCP Cloud Tasks for scheduled posting

I am looking to integrate an automated posting service in my firebase application. The users will create a post with a desired posting time from the client application which will be added to my Firestore database.
I would like to be able to create a Cloud Task to actually add the post to the client dashboard at the desired time, which could be weeks/months in the future.
Is a cloud function Firestore trigger that creates a cloud task the best implementation?
I know that Cloud Scheduler/ Pub/Sub /App Engine is normally the flow recommended for functions run on a normal schedule, i.e once daily/weekly. But I am looking to allow my users to specify the exact time they want their post to be sent.
Is my thinking to use Cloud Tasks correct?
Any insight would be appreciated!
I think that best approach is to use the Cloud Functions for Firebase client SDKs that will let you call functions directly from a Firebase app. To call a function from your app in this way, write and deploy an HTTPS Callable function in Cloud Functions, and then add client logic to call the function from your app. Then, if you want to schedule functions to run at specified times, use functions.pubsub.schedule().onRun() This method creates a Pub/Sub topic and uses Cloud Scheduler to trigger events on that topic, ensuring that your function runs on the desired schedule.

Firebase: Enable the Google Cloud Build API for your Cloud Functions project?

Hi I am using firebase and the firebase functions.
1 day ago I received an email from Google Cloud with the following content:
Starting April 20, 2020, Cloud Functions will use Google Cloud Build, Container Registry, and Google Cloud Storage to build and store your source code, and deploy container image(s) before running them on Google Cloud. You must enable the Cloud Build API for your project(s) to ensure your Cloud Function is built and deployed correctly. Once you enable the API, you may incur charges if your Cloud Build, Container Registry, or Cloud Storage usage exceeds the free tier limits for these products. You can find a list of your projects that are using Cloud Functions and may be affected by this change at the bottom of this email.
I tend to avoid tinkering the Google Cloud (or even logging in there) as I am using the Firebase as an all inclusive solution and so far I did not have the need to login there.
Now the question:
Do I need to follow the instructions and take action, or is this something separate from the Firebase Functions?
The "affected" project that is mentioned on the email is the Firebase project
To be able to use cloud functions after April 20, 2020 you must enable the Cloud Build API because this will be a new deployment framework.
You will not be able to use cloud functions if you do not enable the Cloud Build API after this date.
These changes will apply even for Firebase cloud functions.
I believe you will need to do it only if you are going to deploy Cloud Functions in the future, Cloud Functions already deployed will not be affected.
In case you are worried about billing, Cloud Build provides a free tier where only usage above 120 build-minutes/day will be charged. When your usage is within the free tier, you will not be charged for the Cloud Build portion of Cloud Function deployments. See Cloud Build pricing for more information.
Similarly, Cloud Storage and Container Registry share a free tier where only usage above 5GB-months will be charged. ( * Note : free tier only limited to US regions - US-WEST1, US-CENTRAL1, and US-EAST1 and aggregated over all 3 regions )​ For example, if you have a large deployment that uses 100GB of storage, you will only be charged an additional $2.47 for storage/month (based on these particular U.S. regional storage prices).
You can monitor your usage and see whether you are getting close to hitting the free quotas.
This is a best effort from Google to communicate information that is necessary to the user’s continued use of the product or that is considered a necessary legal update and keep customers away from having future issues
Using Cloud Build, Container Registry and Cloud Storage provides the following benefits:
Detailed function build logs will be available in the GCP Console, aiding in debugging and increasing visibility.
The ability to get build time that exceeds the current build quota of 120 build-mins/day.
The ability to view a built container image for your function in Container Registry.

Firebase Functions quota when serving locally using firebase serve --only functions

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.

Firebase - Cloud Functions : Always running functions

I am new on firebase cloud functions. I would like to ask a question about always running or self-triggering functions. How can we handle these things? How can we implement always running functions or self-triggering?
Google Cloud Functions are snippets of code that run in response to events that happen somewhere else. Some example events:
a HTTPS URL is accessed, either from application code, or in some other way
a User account is created on Firebase Authentication
a node is written in the Firebase Realtime Database
a message is sent to a Cloud PubSub topic
There is no concept on a forever-running function on Cloud Functions (nor on other, similar Functions-as-a-Service offerings), although it's definitely possible to create a function that gets triggered every minute or so (like a cron job).

Resources