Firebase functions: failed to create function - firebase

Following the Firebase examples to create and deploy a function, I keep failing at the deploy phase.
The error, with --debug enabled, shows:
<<< [apiv2][body] POST
https://cloudfunctions.googleapis.com/v1/projects/actus-poc2/locations/us-central1/functions
{"error":{"code":403,"message":"Cloud Functions uses Artifact Registry
to store function docker images. Artifact Registry API is not enabled
in your project. To enable the API, visit
https://console.developers.google.com/apis/api/artifactregistry.googleapis.com/overview?project=...
Now I was expecting to be able to stay within the confines of the firebase console but this message seems to imply I need to open the Google Cloud Console to enable additional permissions.
Should the code samples better document this?
Or is this a recent change in firebase functions that breaks many of the existing examples?

I need to open the Google Cloud Console to enable additional permissions.
The reason why you need to use the Google Cloud Console is because Cloud Functions for Firebase relies on some Google Cloud services. See.
Function deployments with Firebase CLI 11.2.0 and higher rely on Cloud Build and Artifact Registry.
is this a recent change in firebase functions that breaks many of the existing examples?
Deployments to older versions also do rely on some Google Cloud services. Deployments to older versions use Cloud Build in the same way, but rely on Container Registry and Cloud Storage for storage instead of Artifact Registry.
Should the code samples better document this?
If you do think an update to said documentation could be helpful, here is more about opening Feature requests.

Related

Is there a way to configure Trigger Email to operate on Firebase Emulator? [duplicate]

I just installed a Firebase extension, and can see it in my Console. How do I get my local Functions emulator to use the extension as well?
When I start the emulators using the CLI, I can see that the functions emulator is 'Watching [locally defined path] for Cloud Functions...', but no evidence that the Firebase extension is downloaded or otherwise watched somehow.
July 2022: It is now possible to run extensions in the emulator. See the documentation on using the Extensions Emulator to evaluate extensions for full details.
There's currently no built in support for running Extensions on Firebase's Emulator Suite yet.
Luckily Firebase Extensions are mostly "just" predefined Cloud Functions with some installation and configuration data. And since Cloud Functions can be emulated, you can get the same functionality locally with some work.
To run an extension on your local emulator, you will have to get the source of the extension (which is linked from the extension's page), and make the Cloud Functions (and possibly application) code connect to the emulators instead of the cloud-hosted services.
Update: There is a workaround, which of the engineers working on Extensions documented here.

Deploying Firebase Functions hit build quota (Build Create requests per minute)

I have a Firebase project with 55 Functions. I sometimes got a deployment error saying that I hit the quota limit for Build Create requests per minute (the quota right now is 60) with the simplest deployment command,
firebase deploy --only functions
And the CLI suggested me to deploy the remaining again using a command like this,
firebase deploy --only functions:functionA,functions:functionB
As it is a per minute quota, I was expecting the CLI to workaround the quota seamlessly. But it's not.
I sent an email to Firebase Support and they advised me to always use only 75% of the quota at one time when trying to deploy functions, but I wonder how everyone workarounds this quota issue ?
I read about organizing functions in groups in the documentation and deploy group-by-group, but I wonder if there is other solutions ?
Well I think that you can use Cloud Build. BTW not sure if you know, that all your Firebase projects and functions are available in GCP as well. You can change and deploy them directly in GCP Console (direct link).
In Cloud Build there is functionality that lets you to deploy to Firebase with convenient configuration file in yaml or json.
The configuration file contain steps of your deploy and you can setup a timeout between them (reference). So, you can create those steps with --only flag with control of time and you can use it created file many times and just adjust it when you add new function.
I think this will help you to avoid hitting quota limits, and I suppose you can use other features of Cloud Build as well.

Firebase cloud functions init not working

I want to use Firebase cloud functions but when I try to init exists project I get error.
This is the error "Error: HTTP Error: 403, The caller does not have permission"
I created project before and then I moved project folder. When I had tried deploy, it wasn't work. I don't remember which error I got. And then I tried init same project but I got this error.
I tried logout and login again but it wasn't work.
I deleted "firebase-tools" but it wasn't work too.
And after I tried on different computer and I got same error.
And also I have Firebase Admin permission.
The firebase init command initializes/enables the project to use Cloud Functions for Firebase. Owners or Editors should use this command. Owners/Editors have higher permissions which allows APIs to be enabled (e.g. allowing the project to create VMs, Cloud Functions, or create a NoSQL Database).
Therefore I think you should perform this operation with Owner/Editor role.
You need to have Owner or Editor IAM permission on the GCP project to use firebase init command.
The firebase init command initializes/enables the project to use Cloud Functions/Hosting for Firebase. Owners/Editors have higher permissions that allow APIs to be enabled etc.
it is a first-time task when you starting the development, and then init command can be avoided if you have set up your cloud functions code in VCS for multiple developers or you.
i.e, Usually after writing code, you will replicate the project to other developers, who will then also write code and use firebase use yourprojectid further.

Firebase CLI - How to Manage Cloud Functions

Using the firebase-cli you can easily deploy functions and show the logs. But I have yet to find the option to download or retrieve cloud functions.
I've dug through quiet a bit of the -h commands and nothing yet.
Is it possible to download / retrieve a projects cloud functions through the firebase-cli? I tend to switch between computers from home to work and I need to go to the console to copy the source code and redeploy.
The Firebase CLI doesn't provide a way to get deployed code. It's expected that you use some form of source control for managing code between developers and machines.

How to Run Admin functions on Firebase

I'm trying to create a function to delete all users from the Database and write it on index.ts file and deploy it. Now, how can I run it?? I don't want my clients to run it from their mobile app, I need some admin tool to run the management functions. When I see cloud functions on Firebase console there's no option to run the functions, just to view their logs.
Cloud Functions isn't for running one-time scripts. You should do that on your local machine. Cloud Functions is for running code that responds to HTTP requests, or events that occur within other products in your project.
You may want to read this article: https://firebase.googleblog.com/2017/03/how-to-schedule-cron-jobs-with-cloud.html - it suggests using App Engine cron job for that purpose. Relevant project on github: https://github.com/FirebaseExtended/functions-cron
Also there's an example on similar topic in Firebase docs: https://github.com/firebase/functions-samples/tree/master/delete-unused-accounts-cron

Resources