How to use flutter firebase functions for free - firebase

I am getting this error :
Error: Your project myproject must be on the Blaze (pay-as-you-go) plan to complete this command. Required API cloudbuild.googleapis.com
can't be enabled until the upgrade is complete. To upgrade, visit the following URL:
https://console.firebase.google.com/project/fluttershare-d057e/usage/details
while using this command : firebase deploy --only functions
which means I have to purchase flutter functions to proceed. Now I want to know is there any alternative way to deploy function like onCreate() free or can we build these functions manually for firebase ? I am using flutter technology.

Based on #Brugui and #FrankvanPruffelen answers, you need the Blaze plan in order to use Cloud Functions, however, it doesn't necessarily mean you'll have to pay for Cloud Functions usage as there's a significant free tier.

Related

How do Firebase functions handle PubSub topics created with Google Cloud?

I found a two sources that indirectly reference the fact that when creating Google Cloud PubSub subscriptions with Firebase (using the firebase-functions/v1 npm package), Firebase automatically creates the PubSub Topics and PubSub subscriptions:
Cap your Firebase spending #1: Setting up a billing PubSub topic (YouTube)
Firebase PubSub Trigger with Message Ordering (StackOverflow)
As a result, you do not need to (for example) use $ gcloud pubsub topics create $TOPIC_NAME and $ gcloud pubsub subscriptions create $SUBSCRIPTION_NAME to create the topic and subscriptions.
Is this behavior actually documented anywhere?
I would like to create my PubSub subscriptions outside of Firebase. This enables me to create subscriptions using the "dead letter topic" feature and enables me to consistently document my Topics and Subscriptions within my larger Google Cloud Project.
Is it possible to deploy cloud functions within my Firebase project that listen to subscriptions created outside of Firebase?
For example, could I deploy Firebase cloud functions that use the #google-cloud/pubsub npm package instead of firebase-functions/v1?
Firebase automatically creates the PubSub Topics and PubSub subscriptions as you can see that in the process & code described in public docs.
And It is possible to deploy cloud functions within Firebase projects that listen to subscriptions created outside of Firebase. If you want to deploy cloud function which handles dead-letter-topics in firebase you have to follow these steps:
Create a pubsub topic using gcloud command "gcloud pubsub topics
create"
Create a firebase function with trigger pointing to the
topic created in step 1
Deploy the function using firebase
command "firebase deploy --only functions"
Update the subscription
created and enable dead letter feature. This could also be done
using the gcloud command
Make necessary updates to the firebase
function and redeploy the function using firebase deploy --only functions
Reason behind updating subscription is, When deploying the function using the firebase cli, the subscription may be recreated with standard retry settings and results in disabling dead-letter-topic.
So After each function deployment, you need to update the subscription accordingly.
You can use postdeploy hooks in firebase cli through which you can re-enable the dead-letter settings post a deployment automatically. Please see the below steps for the same:
Create a postdeploy.sh script that contains the gcloud command to update a subscription as below. Please see below as just an example and should be modified for variables. Command details are available here
gcloud pubsub subscriptions update projects/$GCLOUD_PROJECT/subscriptions/$SUBSCRIPTION_NAME --dead-letter-topic=$TOPICNAME --max-delivery-attempts=5
Reference the above postdeploy.sh in firebase.json file as a post hook. Example below:
{
"functions": {
"postdeploy": "./postdeploy.sh",
"source": "functions"
}
}
Deploy the firebase function using regular firebase command firebase deploy --only functions:XYZ
For other alternatives go through this Article.
And you can deploy firebase functions which uses the #google-cloud/pubsub

Is Cloud Functions in Firebase Free or Not (Cloud Functions deployment requires the pay-as-you-go (Blaze) billing plan)

When i make my first deploy function I can't deploying Because I have Error Asks me to make Upgrade to my account to Blaze I need to Know Can i deploy Function when i use free account??
Output:
i deploying functions
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
! functions: missing required API cloudbuild.googleapis.com. Enabling now...
+ functions: required API cloudfunctions.googleapis.com is enabled
Error: Cloud Functions deployment requires the pay-as-you-go (Blaze) billing plan. To upgrade your project, visit the following URL:
https://console.firebase.google.com/project/institute-for-admin/usage/details
For additional information about this requirement, see Firebase FAQs:
https://firebase.google.com/support/faq#functions-runtime
As the message says, you can't deploy functions on the Spark free tier, if you target nodejs 10. Read the link to the FAQ:
Why will I need a billing account to use the Node.js 10 runtime for
Cloud Functions for Firebase?
Because of updates to its underlying architecture planned for August
17, 2020, Cloud Functions for Firebase will rely on some additional
paid Google services: Cloud Build, Container Registry, and Cloud Storage. These architecture updates will apply for functions deployed
to the Node.js 10 runtime. Usage of these services will be billed in
addition to existing pricing.
In the new architecture, Cloud Build supports the deployment of
functions. You'll be billed only for the computing time required to
build a function's runtime container.
Cloud Storage, interoperating with Google Container Registry, will
provide storage space for the containers in which functions run.
You'll be billed for each container required to deploy a function. If
you're currently using Cloud Functions within free usage limits, you
may notice new, small charges for each container stored— for example,
1GB of storage is billed at $0.026 per month.
To understand more about how your bill might change, please review the
following
Cloud Functions pricing: existing free tier is unchanged.
Cloud Build pricing: Cloud Build provides for a free tier.
Container Registry pricing.
If you want to target node 8, that might still work. But it's been deprecated, and your functions will eventually stop working. You would still have to migrate them to node 10 in that case, and provide a billing account.
Cloud Functions still has a monthly free allowance that's documented in the pricing page. But you will have to provide a credit card and be on a billing plan in order to use it. You will be responsible for paying for any monthly overage.
Currently, the firebase is using node version 10 for cloud functions which requires you to pay (pay as you go).
You can change the node from 10 to 8 (to use for free of cost) in functions/package.json
"engines": {
"node": "8". // changed from 10 to 8
},
However, this will be soon deprecated. This is what the firebase website says:
Node.js 8 has been deprecated. Starting Feb 15, 2021, we'll no longer
support new deploys or updates of Node.js 8 functions. Starting Mar
15, 2021, we'll no longer support executions of existing Node.js 8
functions.
https://firebase.google.com/support/faq?authuser=0#expandable-10-label
EDIT
This might be a legacy. Please check the latest comments for an updated policy.
Just to clear confusion here
Firebase seems to close the cloud functions for spark plan. So, I thought what if firebase is planning to take away the free plan features one by one.
Here is the answer from their FAQ page.
Does this change to Cloud Functions mean the Firebase free plan (Spark) is going away?
No. This change will not affect the other Firebase products. The Spark
plan is going to be unavailable for Cloud Functions after March 15,
2021.
I don't think Cloud Function is free even if you stay within the free quota as they seem to charge for container storage which seems to automatically get created when you deploy a function.
As of June 8, 2020 the answer is no it is not free anymore
It used to be an option to set the engine to a legacy node 8 but as firebase states
Node.js 8 (deprecated on June 8, 2020) Deployment of functions to the
Node.js 8 runtime was disabled in the Firebase CLI on December 15,
2020. Execution of already-deployed functions will stop at some point in the future; if you have deployed functions to the Node.js 8
runtime, we recommend that you upgrade to the Node.js 14 runtime.
And therefore it is no longer an option
I was also facing the same issue! If you only concerns with learning cloud functions of firebase instead of running command firebase-deploy try firebase-serve it will serve locally firebase cloud functions on your machine and you can use it!
in this time when I write these lines node.js 8 is no longer available 'The Spark plan is unavailable for Cloud Functions after March 15, 2021' so I think that we have migrate to node.js 10 and higher but with no free plan :we have to 'pay as we go' by providing our cards number series. Note that this 'blazer plan' could be free if we do note exceed some limits
for more details please see this Start for free,
then pay as you go
Cloud Functions are only available on the Blaze plan which means you'll need to enter a credit card.
If you want to stop using Cloud Functions, remove the functions section from your firebase.json (if it exists) and also delete the functions folder that firebase init created for you.
If you want to experiment with Cloud Functions for free, you should use the local Firebase Emulator Suite to develop.

How to setup vpc connector for firebase cloud functions?

Firebase Cloud Functions run on top of GCP, so, do they support using a vpc connector?
What I'm trying to achieve is to limit a forward-proxy server to only accept requests from the internal network, but since Cloud Functions doesn't support static IPs, the only way would be via vpc connector.
This seems now to be handled in latest firebase-tools v8.9.0 version.
Must be used in conjunction with firebase-functions v3.11.0 or higher
https://github.com/firebase/firebase-tools/releases/tag/v8.9.0
functions
.runWith({
vpcConnector: 'test-connector',
vpcConnectorEgressSettings: 'PRIVATE_RANGES_ONLY'
})
.auth.user()
.onCreate((user) => user);
Cloud Functions for Firebase doesn't actually run "on top of" GCP. Firebase just adds tools and SDKs that make Cloud Functions easier to use for some developers. The core Cloud Functions product is exactly the same, no matter if you're building and deploying with Firebase tools or gcloud.
You should still be able to configure a VPC connector for functions deployed with the Firebase CLI. You will just not able able to configure it on the command line like you can with gcloud. Instead, you will have to configure the connector in the Cloud console after deploying the function, exactly as described in the documentation you linked to.
Since Firebase is just a wrapper for Google Cloud Functions, just bypass the Firebase CLI and use the one with more parameters. (Google Cloud CLI)
i.e.
$ gcloud functions deploy <function_name> --trigger-http --runtime nodejs10 --vpc-connector projects/<your_project_name>/locations/<your-vpc-region>/connectors/<vpc_name> --service-account <your-role-name>
Source:
https://cloud.google.com/functions/docs/networking/connecting-vpc

How to do integration tests for Firebase HTTP functions with Firestore

Trying to write integrations tests for HTTPS function (implemented as an express app) that use Firestore as DB
Since its an integration test, I don't want to mock the Firestore DB in this case, however, since they perform network calls, they take time to execute
Is there a Firestore local emulator to use in this scenario? There is an option to config Firestore in offline mode, maybe that's the way? Didn't find any documentation in Firebase on this use case
AskFirebase
You have to setup a Firestore emulator locally (assuming you already have firebase-cli installed):
$ firebase setup:emulators:firestore
Then run the emulator:
$ firebase serve --only firestore
With the emulator running, you can run your test suites.
In order to write tests you can use the #firebase/testing package. For more information, check the official documentation here.
There is also an official quickstart repository on GitHub, which shows how to test Firestore locally, both using JavaScript and Typescript. You can find it here.

Is the Cloud Function for Firebase unavailable when the function is updated

When I am updating a Cloud Function for Firebase using the CLI firebase deploy --only functions, is the Function unavailable for a certain amount of time or is that handled by the Cloud Function infrastructure internally and the Function is available at all times and it just switches over to the new Function once the deployment is successful?
Cloud Functions is in beta, and Google currently does not give any guarantees about the availability of your code. But the intent is that you should not miss any invocations when replacing the code. There has been discussion about this already.

Resources