6

I use following firebase cli command to deploy my firebase functions

firebase deploy --only functions

How can I limit the number of instances for functions, when deployed like this? It looks like gcloud command has --max-instances option to limit instances, but couldn't find anything like this for firebase cli.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Lahiru Chandima
  • 22,324
  • 22
  • 103
  • 179
  • 1
    You may want to reconsider the accepted answer. I have just tried @nathan's solution and it works perfectly. The parameter is well documented in the link they provided. ^^ – Peque Jan 07 '21 at 17:23

3 Answers3

11

You can set the maxInstances when you write the function, using runWith and passing in RuntimeOptions

Something like this:

 functions
.runWith({maxInstances: 3})
.https.onCall(() => {});
nathan
  • 126
  • 3
2

There is currently no option on the Firebase CLI for this. Feel free to file a feature request with Firebase support. If such an option is added, it likely won't end up in the CLI, but rather the function builder interface, similar to how region and memory are set.

For now, you can use the Google Cloud console by finding your deployed function there and editing to to use the value you want.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Couldn't find an option in google cloud console to change the instance count. I can only see options to copy function, test function, view logs and delete. Any idea where to edit the max instance count? – Lahiru Chandima Nov 18 '20 at 05:29
  • Click the edit button at the top to edit a deployed function after selecting it. – Doug Stevenson Nov 18 '20 at 05:40
  • Found it! Thanks – Lahiru Chandima Nov 18 '20 at 05:44
  • The `maxInstances` option is not listed on the linked page for the `FunctionBuilder` interface, but it is listed on the page for the `RuntimeOptions` object, linked from the accepted answer. Probably the `FunctionBuilder.runWith` documentation should be updated! Also should probably be mentioned here: https://firebase.google.com/docs/functions/manage-functions – aldel Jul 28 '21 at 13:14
1

If you are writing a function with Python for 2nd gen Cloud Functions then you can use:

@https_fn.on_call(max_instances=10)
def foo(req: https_fn.CallableRequest) -> any:
    ...
Snake
  • 501
  • 7
  • 9