Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase Cloud Functions V2 - Error when deploying

Followed the docs and did the setup as needed, whenever trying to deploy a function, the debug error says

Cannot create trigger projects/***********/locations/us-central1/triggers/******-967155: 
Invalid resource state for \"\": Permission denied while using the Eventarc Service Agent. If you recently started to use Eventarc, it may take a few minutes before all necessary permissions are propagated to the Service Agent. Otherwise, verify that it has Eventarc Service Agent role."

Could not create Cloud Run service onrelationadded. spec.template.spec.containers.resources.limits.cpu: Invalid value specified for cpu. For the specified value, maxScale may not exceed 10.\nConsider running your workload in a region with greater capacity, decreasing your requested cpu-per-instance, or requesting an increase in quota for this region if you are seeing sustained usage near this limit

Coming from the V1 I never saw this error before, after looking a lil bit I found its related to IAM & ADMIN . checked the service default manager permission and tried to enable permission as Functions Editor/Admin but still without success

enter image description here

Command : firebase deploy --only functions

Response:


i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run build

> build
> tsc

✔  functions: Finished running predeploy script.
i  functions: preparing codebase default for deployment
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
i  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled
✔  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged /User/ ******/******/**** (125.52 KB) for uploading
i  functions: ensuring required API run.googleapis.com is enabled...
i  functions: ensuring required API eventarc.googleapis.com is enabled...
i  functions: ensuring required API pubsub.googleapis.com is enabled...
i  functions: ensuring required API storage.googleapis.com is enabled...
✔  functions: required API pubsub.googleapis.com is enabled
✔  functions: required API eventarc.googleapis.com is enabled
✔  functions: required API storage.googleapis.com is enabled
✔  functions: required API run.googleapis.com is enabled
i  functions: generating the service identity for pubsub.googleapis.com...
i  functions: generating the service identity for eventarc.googleapis.com...
✔  functions: functions folder uploaded successfully
i  functions: creating Node.js 18 (2nd Gen) function onRelationAdded(us-central1)...
⚠  functions: Your current project quotas don't allow for the current max instances setting of 100. Either reduce this function's maximum instances, or request a quota increase on the underlying Cloud Run service at https://cloud.google.com/run/quotas.
⚠  functions: You can adjust the max instances value in your function's runtime options:
        setGlobalOptions({maxInstances: 10})
Failed to create function projects/****/locations/us-central1/functions/Added/user

Functions deploy had errors with the following functions:
        AddedUser(us-central1)
i  functions: cleaning up build files...

Error: There was an error deploying functions ```
like image 967
David.C Avatar asked Jul 08 '26 23:07

David.C


1 Answers

To explicitly reduce the default number of instances for all functions in V2, need to use the setGlobalOptions function from the firebase-functions/v2 package.

import { setGlobalOptions } from "firebase-functions/v2";

// Set the maximum instances to 10 for all functions
setGlobalOptions({ maxInstances: 10 });

Use below code if you are not using ES module

const {setGlobalOptions} = require("firebase-functions/v2");
setGlobalOptions({maxInstances: 10});
like image 170
David.C Avatar answered Jul 13 '26 02:07

David.C