Cloud Functions 版本比較
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Cloud Functions for Firebase 有兩個版本:
- Cloud Functions (第 2 代),可將函式部署為 Cloud Run 上的服務,讓您使用 Eventarc 和 Pub/Sub 觸發函式。
- Cloud Functions (第 1 代):這是函式的原始版本,事件觸發條件和可設定性有限。
建議您盡可能選擇 Cloud Functions (第 2 代) 來使用新功能。不過,我們計畫繼續支援 Cloud Functions (第 1 代)。
本頁面說明 Cloud Functions 中推出的功能,並比較這兩個產品版本。
Cloud Functions (第 2 代)
Cloud Functions 是 Firebase 的新一代函式即服務產品。Cloud Functions (第 2 代) 以 Cloud Run 和 Eventarc 為基礎,可為 Cloud Functions 提供更完善的基礎架構和更廣泛的活動涵蓋範圍,包括:
- 以 Cloud Run 為基礎:函式以 Cloud Build 建構,並使用預設的 Cloud Run 執行環境部署為 Cloud Run 服務。您可以像自訂 Cloud Run 服務一樣自訂函式。請參閱 Cloud Run 說明文件,瞭解如何設定服務,例如記憶體限制、環境變數等。
- 要求處理時間較長:執行要求時間較長的工作負載,例如處理來自 Cloud Storage 或 BigQuery 的大量資料串流。
- 較大的執行個體大小:執行較大的記憶體內、運算密集型和平行工作負載。
- 提升並行程度:使用單一函式例項處理多個並行要求,盡量減少冷啟動次數並縮短延遲時間。
- 流量管理:在不同函式修訂版本之間拆分流量,或將函式復原為先前的版本。
- Eventarc 整合:原生支援 Eventarc 觸發條件,將 Eventarc 支援的 90 多個事件來源全數帶到 Cloud Functions。
- 更廣泛的 CloudEvents 支援:所有語言執行階段都支援業界標準的 CloudEvents,提供一致的開發人員體驗。
詳情請參閱比較表。
由於 Cloud Functions 會在 Cloud Run 上將函式部署為服務,因此 Cloud Functions 會與 Cloud Run 共用資源配額和限制。請參閱「配額」。
比較表
功能 |
Cloud Functions (第 1 代) |
Cloud Functions |
映像檔登錄 |
Container Registry或Artifact Registry |
僅限Artifact Registry |
要求逾時 |
最多 9 分鐘 |
- HTTP 觸發函式最多 60 分鐘
- 以事件觸發的函式最多 9 分鐘
|
服務帳戶* |
Google App Engine 服務帳戶 (PROJECT_ID@appspot.gserviceaccount.com) |
Google Cloud 預設 Compute 服務帳戶 (PROJECT_NUMBER-compute@developer.gserviceaccount.com)
|
執行個體大小 |
2 個 vCPU,最高 8 GB RAM |
4 個 vCPU 最多可搭配 16 GiB RAM |
並行 |
每個函式執行個體 1 項並行要求 |
每個函式執行個體最多可處理 1000 項並行要求 |
* 這是用來從執行中的函式存取 Firebase 或 Cloud API 的預設服務帳戶。當您初始化時未提供引數,Firebase Admin SDK 就會使用這個檔案。
定價
如需價格資訊,請參閱 Firebase 定價方案。
如要查看與 Cloud Functions 相關的費用,請按照下列步驟操作:
- 前往 Google Cloud 控制台的「Cloud Billing 報告」頁面。
- 如果系統提示,請選取與 Google Cloud 專案相關聯的帳單帳戶。
- 在「Filters」(篩選器) 面板的「Labels」(標籤) 下方,新增標籤篩選器,並將鍵設為
goog-managed-by
,值設為 cloudfunctions
。
限制
Cloud Functions for Firebase (第 2 代) 不支援Analytics事件。
雖然 Cloud Functions for Firebase (第 2 代) 支援驗證封鎖事件,但它不支援與第 1 代相同的基本 Authentication 事件集。
不過,由於第 1 代和第 2 代函式可以並存於同一個來源檔案中,您仍可在第 1 代中開發及部署 Analytics 和基本 Authentication 觸發條件,並與第 2 代函式搭配使用。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-17 (世界標準時間)。
[null,null,["上次更新時間:2025-08-17 (世界標準時間)。"],[],[],null,["\u003cbr /\u003e\n\nThere are two versions of Cloud Functions for Firebase:\n\n- **Cloud Functions (2nd gen)** , which deploys your functions as services on Cloud Run, allowing you to trigger them using Eventarc and Pub/Sub.\n- **Cloud Functions (1st gen)**, the original version of functions with limited event triggers and configurability.\n\nWe recommend that you choose Cloud Functions (2nd gen) for new functions\nwherever possible. However, we plan to continue supporting Cloud Functions\n(1st gen).\n\nThis page describes features introduced in Cloud Functions and\nprovides a comparison between the two product versions.\n\nCloud Functions (2nd gen)\n\nCloud Functions is Firebase's next-generation\nFunctions-as-a-Service offering. Built on Cloud Run and\nEventarc, Cloud Functions (2nd gen) brings enhanced\ninfrastructure and broader event coverage to Cloud Functions, including:\n\n- **Built on Cloud Run** : Functions are built with Cloud Build and deployed as Cloud Run services using the default [Cloud Run execution environment](//cloud.google.com/run/docs/about-execution-environments). This gives you the ability to customize your function as you would a Cloud Run service. Refer to Cloud Run documentation to explore options for configuring your service, such as [memory\n limits](//cloud.google.com/run/docs/configuring/services/memory-limits), [environment variables](//cloud.google.com/run/docs/configuring/services/environment-variables), and so forth.\n- **Longer request processing times** : Run longer-request workloads such as processing large streams of data from Cloud Storage or BigQuery.\n- **Larger instance sizes**: Run larger in-memory, compute-intensive, and parallel workloads.\n- **Improved concurrency**: Handle multiple concurrent requests with a single function instance to minimize cold starts and improve latency.\n- **Traffic management**: Split traffic between different function revisions or roll a function back to a prior version.\n- **Eventarc integration** : Native support for Eventarc triggers, bringing all 90+ event sources supported by Eventarc to Cloud Functions.\n- **Broader CloudEvents support** : Support for industry-standard [CloudEvents](https://cloudevents.io/) in all language runtimes, providing a consistent developer experience.\n\nSee the [comparison table](#comparison-table) for details.\n\nBecause Cloud Functions deploys functions as services on Cloud Run,\nCloud Functions shares resource quotas and limits with\nCloud Run. See [Quotas](/docs/functions/quotas).\n\nComparison table\n\n| Feature | Cloud Functions (1st gen) | Cloud Functions |\n|-------------------|------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|\n| Image registry | Container Registry or Artifact Registry | Artifact Registry only |\n| Request timeout | Up to 9 minutes | - Up to 60 minutes for HTTP-triggered functions - Up to 9 minutes for event-triggered functions |\n| Service account\\* | Google App Engine service account (\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e@appspot.gserviceaccount.com) | Google Cloud default compute service account (\u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e-compute@developer.gserviceaccount.com) |\n| Instance size | Up to 8GB RAM with 2 vCPU | Up to 16GiB RAM with 4 vCPU |\n| Concurrency | 1 concurrent request per function instance | Up to 1000 concurrent requests per function instance |\n\n\\* This is the default service account used to access Firebase or Cloud APIs\nfrom a running function. It is used by the Firebase Admin SDK when you\n[initialize without arguments](/docs/admin/setup#initialize-sdk).\n\nPricing\n\nFor pricing information, see [Firebase pricing plans](https://firebase.google.com/pricing#cloud-functions).\n\nYou can view your costs associated with Cloud Functions as follows:\n\n1. Go to the [Cloud Billing Reports page](https://console.cloud.google.com/billing/reports) in the Google Cloud console.\n2. If prompted, select the billing account associated with your Google Cloud project.\n3. In the **Filters** panel, under **Labels** , [add a label filter](//cloud.google.com//billing/docs/how-to/reports#filters) with the key `goog-managed-by` and the value `cloudfunctions`.\n\n| **Note:** If you are using Cloud Functions for Firebase (1st gen) and are interested in Cloud Functions, see [Upgrade 1st gen Node.js functions to 2nd gen](/docs/functions/2nd-gen-upgrade).\n\nLimitations\n\nCloud Functions for Firebase (2nd gen) does not provide support for Analytics\nevents.\n\nThough Cloud Functions for Firebase (2nd gen) supports authentication blocking\nevents, it does not support the same set of basic Authentication events as\n1st gen.\n\nHowever, because 1st gen and 2nd gen\nfunctions can coexist side-by-side in the same source file, you can still\ndevelop and deploy Analytics and basic Authentication triggers in 1st gen\ntogether with 2nd gen functions."]]