0

While I find the Cloud Functions in Firebase fairly convenient, I have troubles figuring out how to configure them in any way. the firebase init generated the firebase.json that contains functions.predeploy property, but are there any other options available? I cannot find any schema for this file. By default my cloud function is deployed as Node.js 6 application. How do I define that I want to use Node.js 8 which is already supported by the platform? How can I change the amount of used memory? How do I define the environment variables? All of these can be specified through cli commands or from UI, but will be overriden during the next deployment. Isn't there something I could add to my firebase.json that would allow me to specify these values as a permanent thing? Or is it that I actually have to work with the full-blown Google Cloud and the Deployment Manager in order to get it to work?

4
  • 1
    Take a look at this firebase.google.com/docs/cli/?hl and this firebase.google.com/docs/functions/get-started?hl Commented Nov 7, 2018 at 14:55
  • I read it already before. This is not what I'm looking for. I created a function and deployed it successfully, but if I simply type firebase deploy [--only functions] they will use Node 6 instead of 8 and 256MB of memory, while I only need 128 and don't want to pay for double of what I need. If I was deploying a lambda on AWS, I would define the full execution environment in the CloudFormation template. I'm basically looking for the equivalent of such template in Firebase Commented Nov 7, 2018 at 15:01
  • did you tried uninstalling your current node 6 and reinstalling with admin privileges your node 8 ? Commented Nov 7, 2018 at 15:02
  • like... what? on my local machine? I never had node 6. I only have Node 8 at the moment. I'm talking about the execution environment in the Firebase though... I don't think my local installation has anything to do with it. As for Firebase, it's a configuration option. You literally have to manually go to your functions after you deploy them and explicitly press for each one of them separately that you want to use "Node 8 Beta"... or Python :P still those options are all there, but you never had the option to specify them during the deployment... and this is where they should have been provided Commented Nov 7, 2018 at 15:07

1 Answer 1

1

All of your questions are answered in the documentation.

Set the node version.

Set the version by adding an engines field to the package.json file that was created in your functions/ directory during initialization. For example, if you prefer to use only version 8, edit package.json to add this line:

"engines": {"node": "8"} 

Specify other runtime config.

To set memory allocation and timeout in functions source code, use the runWith parameter introduced in Firebase SDK for Cloud Functions 2.0.0. This runtime option accepts a JSON object conforming to the RuntimeOptions interface, which defines values for timeoutSeconds and memory. For example, this storage function uses 1GB of memory and times out after 300 seconds:

const runtimeOpts = { timeoutSeconds: 300, memory: '1GB' } exports.myStorageFunction = functions .runWith(runtimeOpts) .storage .object() .onFinalize((object) = > { // do some complicated things that take a lot of memory and time }); 

Set environment config.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.