Firebase Cloud Functions V2 - 部署时出错

Dav*_*d.C 5 google-cloud-platform firebase-cloud-messaging

遵循文档并根据需要进行设置,每当尝试部署功能时,调试错误都会显示

\n
Cannot create trigger projects/***********/locations/us-central1/triggers/******-967155: \nInvalid 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."\n\nCould 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\n
Run Code Online (Sandbox Code Playgroud)\n

从 V1 开始,我以前从未见过这个错误,经过一番查看后,我发现它与IAM & ADMIN有关。检查服务默认管理员权限并尝试启用功能编辑器/管理员权限,但仍然没有成功

\n

在此输入图像描述

\n

命令 :firebase deploy --only functions

\n

回复:

\n
\ni  deploying functions\nRunning command: npm --prefix "$RESOURCE_DIR" run build\n\n> build\n> tsc\n\n\xe2\x9c\x94  functions: Finished running predeploy script.\ni  functions: preparing codebase default for deployment\ni  functions: ensuring required API cloudfunctions.googleapis.com is enabled...\ni  functions: ensuring required API cloudbuild.googleapis.com is enabled...\ni  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...\n\xe2\x9c\x94  functions: required API cloudbuild.googleapis.com is enabled\n\xe2\x9c\x94  artifactregistry: required API artifactregistry.googleapis.com is enabled\n\xe2\x9c\x94  functions: required API cloudfunctions.googleapis.com is enabled\ni  functions: preparing functions directory for uploading...\ni  functions: packaged /User/ ******/******/**** (125.52 KB) for uploading\ni  functions: ensuring required API run.googleapis.com is enabled...\ni  functions: ensuring required API eventarc.googleapis.com is enabled...\ni  functions: ensuring required API pubsub.googleapis.com is enabled...\ni  functions: ensuring required API storage.googleapis.com is enabled...\n\xe2\x9c\x94  functions: required API pubsub.googleapis.com is enabled\n\xe2\x9c\x94  functions: required API eventarc.googleapis.com is enabled\n\xe2\x9c\x94  functions: required API storage.googleapis.com is enabled\n\xe2\x9c\x94  functions: required API run.googleapis.com is enabled\ni  functions: generating the service identity for pubsub.googleapis.com...\ni  functions: generating the service identity for eventarc.googleapis.com...\n\xe2\x9c\x94  functions: functions folder uploaded successfully\ni  functions: creating Node.js 18 (2nd Gen) function onRelationAdded(us-central1)...\n\xe2\x9a\xa0  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.\n\xe2\x9a\xa0  functions: You can adjust the max instances value in your function\'s runtime options:\n        setGlobalOptions({maxInstances: 10})\nFailed to create function projects/****/locations/us-central1/functions/Added/user\n\nFunctions deploy had errors with the following functions:\n        AddedUser(us-central1)\ni  functions: cleaning up build files...\n\nError: There was an error deploying functions ```\n
Run Code Online (Sandbox Code Playgroud)\n

Dav*_*d.C 25

要显式减少 V2 中所有函数的默认实例数量,需要使用包setGlobalOptions中的函数firebase-functions/v2

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

// Set the maximum instances to 10 for all functions
setGlobalOptions({ maxInstances: 10 });
Run Code Online (Sandbox Code Playgroud)

如果您不使用 ES 模块,请使用以下代码

const {setGlobalOptions} = require("firebase-functions/v2");
setGlobalOptions({maxInstances: 10});
Run Code Online (Sandbox Code Playgroud)

  • 您还可以直接从“firebase-functions/v2/options”导入它。我之所以提到这一点,是因为根据文档,“v2 子包是模块化的,我们建议仅导入您需要的特定模块。” (2认同)

小智 5

所以在 python 中找到解决方案有点困难,因为大多数云函数用户都是 javascript 程序员,我只是想在 python 中分享我的解决方案,以防你在任何地方都找不到它。

首先,您需要导入 firebase_functions 的选项

from firebase_functions import options
Run Code Online (Sandbox Code Playgroud)

那么你需要设置你的最大实例

options.set_global_options(max_instances=10)
Run Code Online (Sandbox Code Playgroud)

就是这样,就这么简单