Disable Cloud Functions for Firebase through Firebase dashboard (or cli)

Viewed 9054

Is there a way to disable a Cloud Function for Firebase through the Firebase dashboard?

I deployed a Cloud Function with a bug which caused an infinite loop of the function being triggered, updating the data, then the function triggering again. I discovered the error quickly, but I had to fix the code and redeploy the entire project to get the function to stop triggering.

Even though I deployed the new function, the deployment took some time and the function was triggered hundreds of times (which actually caused others to be triggered hundreds of times).

I'd like to be able to disable a function immediately when this happens, but I don't see any options in the dashboard or through the Firebase CLI.

5 Answers

Dont want to delete the function as I want to keep the usage history, logs, health ect? This work around,long winded, but does the trick:

Disable function:

  • comment out the code in then function in your index.js
  • deploy just the firebase function:

firebase deploy --only functions:functionName

Enable function:

  • uncomment code
  • redeploy just the function with above line

Unfortunately Firebase has only a delete option and no disable option :(

A thing that I'm doing which isn't particularly neat but does the job. is just add a node in the database. for me I have a weekly script I run where I don't want my cloud functions to run when that's running. so at the top of my function I read that node and if the script is running, I just return early. not ideal but saves me having to comment out and redeploy every time

For me the fastest way is to edit function code directly in Google Cloud Console editor. In case of the HTTP function adding something like this at the beginning of a handler

res.status(500).send('The function is disabled');
    return;

I use a solution similar to Red Baron. I have a Firestore Collection of booleans (one for each function) and I check that boolean at the beginning of my function to determine if it's allowed to run. The function will indeed be called, but it won't do anything if that boolean is set to false. It's not a perfect solution because it doesn't completely disable the function. But at least it will retain the log history.

Related