I'm confused by the versioning of Firebase Cloud Functions. In my web console, my Firebase Cloud Functions dashboard says all of my functions are version 1. I've read that version 2 is only available to cloud functions through GCP, not Firebase. However, in Firebase dox, when researching runtime option configuration (i.e. enabling retry on trigger functions or expanding the timeout window), I saw this:
To set memory allocation and timeout in functions source code, use the runWith parameter introduced in Firebase SDK for Cloud Functions 2.0.0.
https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation
This says that Firebase Cloud Functions can opt for v2. If they can, how can I upgrade my functions to v2? If not, can my v1 functions make use of runtime options such as below?
exports.assignAdminPrivileges = functions.runWith({
failurePolicy: true,
}).firestore.document("admins/{doc}").onCreate(async (snapshot, _context) => {
const doc = snapshot.data();
const email = doc.private.email;
return admin.auth().getUserByEmail(email).then((user) => {
return admin.auth().setCustomUserClaims(user.uid, {"admin": true});
});
});
Posting this as a community wiki to help other community members.
As stated by @Frank, There's already instructions/guide on how to upgrade your 1st gen function into 2nd gen function by following this documentation.
Cloud Functions for Firebase (2nd gen) is still in beta but now available for public preview. There are still limitations when using the 2nd gen that includes the use of Firestore triggers which is what you are using now. You can opt for v2 (2nd gen) but as previously stated there's still a limitation on how you can use it. For more information on the limitation, you may want to visit this documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With