6

I'm trying to use a functions.config() variable of the firebase functions environment, to be able to switch logs on/off depending on, whether this variable is set to true/false. I have already created it, but it seems based on info from the following link (https://firebase.google.com/docs/functions/config-env#additional_environment_commands), that you can change it only if you redeploy the function, after you have used the firebase functions:config:set command to change the environmental variable first.

It appears that it could be achieved though, by using gcloud functions commands for deploying the function (gcloud deploy and not firebase deploy), with the --set-env-vars command (and different syntax to access the env. variable). Then this environmental variable can be changed easily by just changing value of the variable by navigating to the specific function at GCP console, and then by going to EDIT -> MORE and changing Environment variables at the bottom. source:
https://cloud.google.com/functions/docs/env-var

So my question is the following: Is there a similar way to change a firebase functions.config() variable without redeploying the function from the cli?

Antonis S
  • 733
  • 6
  • 15
  • 1
    The answer below isn't correct. You are currently required to deploy your function again if you want to update the configuration found in `firebase.confg()`. – Doug Stevenson Jan 02 '19 at 18:16

3 Answers3

3

Update: (credit to Doug Stevenson) Apparantly the only way to change the environment variable is to do a deploy.

Original answer: You can do it the same way. Basically every Firebase Cloud Function is a Google Cloud Function and can be accessed the same way from the GCP console. Every Firebase Cloud Function is also present in the GCP console, and there you can easily just edit the environment variables just as you described in your question)

Andrii Rudavko
  • 370
  • 1
  • 7
  • 1
    Thanks for the answer. – Antonis S Jan 02 '19 at 16:11
  • No problem. You could mark the answer as a correct one) – Andrii Rudavko Jan 02 '19 at 16:15
  • 2
    This answer isn't correct. The variables deployed by the Firebase CLI are **not** the same ones that you see in the Cloud console. The ones you see in the cloud console are set when you deploy with gcloud using the --set-env-vars flag. To update the Firebase config variables found in `firebase.config()`, you do need to deploy the function again. The Firebase team is looking into improvements for function configuration, so be aware that there may be updates to the way this works. – Doug Stevenson Jan 02 '19 at 18:15
  • Thanks for the clarification. Was an overreaching assumption on my part – Andrii Rudavko Jan 02 '19 at 18:24
  • @DougStevenson + Andrii Is there a way to only deploy the one function that uses the variables or do we have to redeploy all functions as instructed? – MadMac May 18 '22 at 22:19
1

Just to add to Andrii's answer you need to redeploy any function that requires the new config. Each deployed function is isolated from all other functions so won't get config updates without a redeploy.

Fi_
  • 11
  • 1
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – abdo Salm Sep 26 '22 at 19:19
0

Andrii is totally right - you have to deploy your functions in order to update the environmental variables.

However, I just wanted to post a quick hack in case you have some CI/CD jobs and you don't really deploy your functions manually.

In this case, what I do, although a bit tedious, is the following:

  1. Add a mock function of some sort, e.g.
exports.helloWorld = functions
  .https.onRequest((req, res) => res.status(200).json({ message: 'Great success!' }))
  1. I run firebase deploy --only functions:helloWorld to make sure I only deploy this function to prevent breaking the functions that are currently used in production.
  2. Go to Firebase Console, open up your project's Functions section and delete helloWorld.
Yulian
  • 6,262
  • 10
  • 65
  • 92