【问题标题】:What is the difference between Cloud Functions and Firebase Functions?Cloud Functions 和 Firebase Functions 有什么区别?
【发布时间】:2017-08-08 20:30:19
【问题描述】:

Cloud FunctionsFirebase Functions (or "Cloud Functions for Firebase") 看起来都一样。请描述每个的用例。

两者都使用 HTTP 函数。

云函数中:

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

Firebase 函数中:

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

这些有什么区别?

【问题讨论】:

  • Firebase 的术语实际上是 Cloud Functions for Firebase,它几乎就是与 Firebase 服务集成的 Cloud Functions。
  • 那么两者没有区别?
  • 想补充一点,不能完全回答你的问题。您可以使用 Google Cloud Functions 以不同的语言(NodeJS、Python。听说 Go 即将推出)进行编码。

标签: firebase google-cloud-platform google-cloud-functions


【解决方案1】:

没有名为 Firebase Functions 的产品。

有三个不同的东西:

  1. Google Cloud Functions,它允许您在 Google 的基础架构中运行代码的 sn-ps 以响应事件。
  2. Cloud Functions for Firebase,根据 Firebase 中的事件(例如数据库或文件写入、用户创建等)触发 Google Cloud Functions
  3. Firebase SDK for Cloud Functions,其中包含一个库(令人困惑地称为 firebase-functions),您可以在 Functions 代码中使用该库来访问 Firebase 数据(例如写入数据库的数据的快照)

因此,Firebase 围绕 Google Cloud Functions 提供了一个(相对较薄的)包装器,以使后者的产品更易于使用并将其与 Firebase 集成。从这个意义上说,它类似于 Firebase 如何将 Google Cloud Storage 集成到“Cloud Storage for Firebase”(以前称为 Firebase Storage)中。

如果您在没有 Firebase 的情况下使用 Google Cloud Platform,则应使用纯 Google Cloud Functions。如果您使用 Firebase 或者您是对 Cloud Functions 感兴趣的移动开发人员,您应该使用 Cloud Functions for Firebase

【讨论】:

  • 仅供参考:Firebase 工具允许开发人员访问所有 Google Cloud 事件。 “firebase-functions”SDK 和 Firebase CLI 协同工作,让开发人员可以通过简单的部署命令来管理一组函数 - 轻松上手,同时您仍然可以在需要时完全访问 Google Cloud Platform。
  • 但是定价不是不同吗?在 Firebase 上下文之外使用 Google Cloud Platform 功能每月可以免费获得 5 GB 的出站数据。从 Firebase 上下文中调用 GCP 函数会禁止访问免费层的非 Google 服务。 25 美元级别或 Blaze 级别(即用即付)允许外部网络访问,但即使在 Blaze 级别,每百万次调用您需要支付 40 美分,但通过 GCP,您的前 200 万次调用是免费的,然后是每百万 .40 美分。
  • 它们在完全相同的基础架构上运行,因此它们的执行方式没有任何区别。在 Blaze 计划中,有相同的免费配额。来自pricing page:“在 Blaze 计划中,Cloud Functions 提供永久免费套餐。每月免费提供前 2,000,000 次调用、400,000 GB-sec、200,000 CPU-sec 和 5 GB 的 Internet 出口流量。您仅对超过此免费配额的使用收费。”
  • Cloud Functions for Firebase 不支持用 python 编写的函数,对吗?基于sentence“你需要一个 Node.js 环境来编写函数(...)”
【解决方案2】:

还有一个区别:Firebase Functions 只能在 JS 或 Node.JS 中实现,而 Cloud Functions 还允许使用 Python 和 Go。

如果您使用 Spark 计划,那么它们的定价方式也存在细微差别。看看https://firebase.google.com/pricinghttps://cloud.google.com/functions/pricing 如果您使用 Blaze 计划,价格是相同的。

我碰巧将两者都用于我的 Firebase 项目。

【讨论】:

    【解决方案3】:

    Google Cloud Platform, GCP 有一篇文章解决了这个问题,Google Cloud Functions and Firebase

    Google Cloud Functions 和 Firebase

    Google Cloud Functions 是 Google 的无服务器计算解决方案 创建事件驱动的应用程序。它是双方的联合产品 Google Cloud Platform 团队和 Firebase 团队。

    对于 Google Cloud Platform 开发人员Cloud Functions 用作连接词 允许您在 Google Cloud Platform (GCP) 之间编织逻辑的层 通过侦听和响应事件来提供服务。

    对于 Firebase 开发人员Cloud Functions for Firebase 提供了一种方法 扩展 Firebase 的行为并集成 Firebase 功能 通过添加服务器端代码。

    两种解决方案都提供快速可靠的功能执行 完全托管的环境,您无需担心 管理任何服务器或配置任何基础设施。

    ...

    Cloud Functions for Firebase 已针对 Firebase 开发人员进行了优化:

    • Firebase SDK 通过代码配置您的功能
    • 与 Firebase 控制台和 Firebase CLI 集成
    • 与 Google Cloud Functions 相同的触发器,以及 Firebase 实时数据库、Firebase 身份验证和 Firebase Analytics 触发器

    【讨论】:

      【解决方案4】:

      描述差异的官方 Google 视频:GCP vs. Firebase - Functions & Firestore

      1. Firebase 可让您将函数包装成可通过 Firebase SDK 调用的可调用函数
      2. 语言支持,GCP 还支持 Go、Python 和 java
      3. GCP 可以通过控制台或 CLI 部署,但 firebase 功能只能通过 CLI 进行

      【讨论】:

        猜你喜欢
        • 2019-09-29
        • 1970-01-01
        • 2023-03-13
        • 1970-01-01
        • 1970-01-01
        • 2018-06-11
        • 2020-01-04
        • 2017-09-24
        • 1970-01-01
        相关资源
        最近更新 更多