Cloud Functions和Firebase Functions之间有什么区别?


84

Cloud FunctionsFirebase Functions(或“ Firebase的Cloud Functions”)看起来都相同。请描述每个的用例。

两者都使用HTTP函数。

云端功能

exports.helloHttp = function helloHttp (req, res) {
  res.send(`Hello ${req.body.name || 'World'}!`);
};

And in the Firebase Functions:

exports.helloWorld = functions.https.onRequest((request, response) => {
  response.send("Hello from Firebase!");
});

What is difference between these?


1
The term for Firebase is actually Cloud Functions for Firebase, which is pretty much just Cloud Functions integrated with Firebase Services.
AL.

2
So there is no difference between both?
Muhammad chhota

Would like to add a simple point not exactly answers your question. You can code in different languages (NodeJS, Python. Heard Go is coming) using Google Cloud Functions.
viggy28

Answers:


157

There is no product called Firebase Functions.

There are three separate things:

  1. Google Cloud Functions, which allow you to run snippets of code in Google's infrastructure in response to events.
  2. Cloud Functions for Firebase, which triggers Google Cloud Functions based on events in Firebase (such as database or file writes, user creation, etc)
  3. Firebase SDK for Cloud Functions, which includes a library (confusingly called firebase-functions) that you use in your Functions code to access Firebase data (such as the snapshot of the data that was written to the database)

So Firebase provides a (relatively thin) wrapper around Google Cloud Functions, to make the latter product easier to use and integrate it with Firebase. In that senses it is similar to how Firebase integrates Google Cloud Storage into "Cloud Storage for Firebase" (formerly known as Firebase Storage).

If you're using Google Cloud Platform without Firebase, then you should use plain Google Cloud Functions. If you're on Firebase or if you're a mobile developer interested in Cloud Functions, you should use Cloud Functions for Firebase.


1
FYI: Firebase tools allow developers to access all of Google Cloud events. The "firebase-functions" SDK and Firebase CLI work together to allow developers to manage a set of functions with simple deploy command -- easy getting started, while you still have full access to Google Cloud Platform when you need it.
Ultrasaurus

Isn't pricing different, however? Using Google Cloud Platform functions outside of the Firebase context gives me 5 GB of outbound data each month for free. Calling GCP functions from inside the Firebase context prohibits access to non-google services at the free tier. Outside networking access is allowed at the $25 level, or at the Blaze level (pay as you go), but even at the Blaze level, you are charged 40 cents per million invocations, but through GCP, your first 2 million invocations are free, and then are .40 cents per million.
mancini0

They run on the exact same infrastructure, so there can't be any difference in how they execute. On the Blaze plan, there is the same free quota. From the pricing page: "On the Blaze plan, Cloud Functions provides a perpetual free tier. The first 2,000,000 invocations, 400,000 GB-sec, 200,000 CPU-sec, and 5 GB of Internet egress traffic is provided for free each month. You are only charged on usage past this free allotment."
Frank van Puffelen

Cloud Functions for Firebase does not support the functions to be written in python, am I right? Based on the sentence "You'll need a Node.js environment to write functions (...)"
JohnAndrews


5

Google Cloud Platform, GCP, has an article addressing this question, Google Cloud Functions and Firebase.

Google Cloud Functions and Firebase

Google Cloud Functions is Google's serverless compute solution for creating event-driven applications. It is a joint product between the Google Cloud Platform team and the Firebase team.

For Google Cloud Platform developers, Cloud Functions serve as a connective layer allowing you to weave logic between Google Cloud Platform (GCP) services by listening for and responding to events.

For Firebase developers, Cloud Functions for Firebase provides a way to extend the behavior of Firebase and integrate Firebase features through the addition of server-side code.

Both solutions provide fast and reliable execution of functions in a fully managed environment where there's no need for you to worry about managing any servers or provisioning any infrastructure.

...

Cloud Functions for Firebase is optimized for Firebase developers:

  • Firebase SDK to configure your functions through code
  • Integrated with Firebase Console and Firebase CLI
  • The same triggers as Google Cloud Functions, plus Firebase Realtime Database, Firebase Authentication, and Firebase Analytics triggers

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.