Reputation: 2025
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?
Upvotes: 0
Views: 1125
Reputation: 317352
All of your questions are answered in the documentation.
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"}
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 });
Upvotes: 1