将 Firebase 功能切换到 Gen-2
Switch Firebase Function to Gen-2
我刚刚看到我们有第 2 代 Cloud Functions,它看起来很棒:https://cloud.google.com/functions/docs/2nd-gen/overview
但是如何将我的第一代功能切换为第二代功能?我知道我可以 create a new function as 2nd gen like this:
const functions = require('@google-cloud/functions-framework');
functions.http('helloHttp', (req, res) => {
res.send(`Hello ${req.query.name || req.body.name || 'World'}!`);
});
但是旧功能呢?有没有办法,或者我必须一个一个地删除并重新创建它们?
Cloud Function Gen2 仅适用于 Cloud Functions 产品,不适用于 Firebase 功能。
Firebase 函数使用库 firebase-functions
而 Cloud Functions 使用 @google-cloud/functions-framework
.
在 Google 云控制台中,这两个函数看起来是一样的,但如果您尝试在云函数 gen1 上部署云函数 gen2,您将收到以下错误:
Failed to create function, function projects/[PROJECT_NUMBER]/locations/[LOCATION]/functions/[FUNCTION_NAME] already exists under 'Gen 1' environment. Please delete conflicting function first or deploy the function with a different name.
您需要完全从 Firebase 函数迁移到 brand-new 创建的 Cloud Functions gen2。
我刚刚看到我们有第 2 代 Cloud Functions,它看起来很棒:https://cloud.google.com/functions/docs/2nd-gen/overview
但是如何将我的第一代功能切换为第二代功能?我知道我可以 create a new function as 2nd gen like this:
const functions = require('@google-cloud/functions-framework');
functions.http('helloHttp', (req, res) => {
res.send(`Hello ${req.query.name || req.body.name || 'World'}!`);
});
但是旧功能呢?有没有办法,或者我必须一个一个地删除并重新创建它们?
Cloud Function Gen2 仅适用于 Cloud Functions 产品,不适用于 Firebase 功能。
Firebase 函数使用库 firebase-functions
而 Cloud Functions 使用 @google-cloud/functions-framework
.
在 Google 云控制台中,这两个函数看起来是一样的,但如果您尝试在云函数 gen1 上部署云函数 gen2,您将收到以下错误:
Failed to create function, function projects/[PROJECT_NUMBER]/locations/[LOCATION]/functions/[FUNCTION_NAME] already exists under 'Gen 1' environment. Please delete conflicting function first or deploy the function with a different name.
您需要完全从 Firebase 函数迁移到 brand-new 创建的 Cloud Functions gen2。