Lahiru Chandima
Lahiru Chandima

Reputation: 24068

How to limit instance count of firebase functions

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.

Upvotes: 7

Views: 3052

Answers (4)

Ifeora-emeka
Ifeora-emeka

Reputation: 107

For the latest Firebase V2, you can set maxInstances globally like this:

const { setGlobalOptions } = require("firebase-functions/v2"); // import it here

setGlobalOptions({ maxInstances: 10 }); // set it here

exports.helloWorld = onRequest((request, response) => {
  logger.info("Hello logs!", {structuredData: true});
  response.send("Hello from Firebase!");
});

Upvotes: 2

Snake
Snake

Reputation: 531

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:
    ...

Upvotes: 3

nathan
nathan

Reputation: 126

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(() => {});

Upvotes: 11

Doug Stevenson
Doug Stevenson

Reputation: 317467

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.

Upvotes: 2

Related Questions