Switch Firebase Function to Gen-2

Viewed 2031

i just saw that we have Cloud Functions 2nd generation which looks great: https://cloud.google.com/functions/docs/2nd-gen/overview

But how can i switch my 1nd gen function to be 2nd gen? I see that i can 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'}!`);
});

but what about old functions? Is there a way or i will have to delete and re-create them one-by-one?

1 Answers

Cloud Function Gen2 is only available for the product Cloud Functions, not Firebase functions.
Firebase functions use the library firebase-functions while Cloud Functions uses @google-cloud/functions-framework.
From the Google Cloud console both functions will appear the same but if you try to deploy a Cloud Function gen2 over a Cloud Function gen1, you will receive the following error:

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.

You will need to migrate completely from Firebase functions to brand-new created Cloud Functions gen2.

Related