You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

无法通过firebase deploy部署Pub/Sub类型Firebase Cloud Functions求助

问题描述

我尝试将一个简单的Pub/Sub函数部署到Firebase Functions中,已完成以下操作:

  • 在Cloud Pub/Sub中创建名为subscription-listener的主题
  • 启用Cloud Run服务(暂未创建任何服务实例)
  • 通过firebase init初始化Firebase Functions项目
  • 为Cloud项目启用计费功能

执行firebase deploy命令时出现如下错误:

⚠  functions: HTTP Error: 400, Could not create Cloud Run service helloworld. spec.template.spec.containers.resources.limits.cpu: Invalid value specified for cpu. For the specified value, maxScale may not exceed 10.
Consider 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, see https://cloud.google.com/run/quotas. Your project may gain access to further scaling by adding billing information to your account.
⚠  functions: failed to create function projects/my-project/locations/us-central1/functions/helloWorld
Failed to create function projects/my-project/locations/us-central1/functions/helloWorld

我的Firebase Functions代码如下:

import { logger, pubsub } from "firebase-functions/v2";

exports.helloWorld = pubsub.onMessagePublished(
  "subscription-listener",
  (event) => {
    logger.log("Event data: ", event.data.message);
  }
);
解决方案

这个错误是Firebase Functions v2默认的CPU配置与自动扩缩容上限冲突导致的,和你遗漏步骤无关,按以下方式调整即可:

  • 显式指定函数资源配置
    在函数定义中明确设置CPU限制和扩缩容上限,确保匹配当前区域的配额规则。例如将CPU设为1核,maxScale控制在10以内:

    import { logger, pubsub } from "firebase-functions/v2";
    
    exports.helloWorld = pubsub.onMessagePublished(
      {
        topic: "subscription-listener",
        cpu: 1,
        maxScale: 10
      },
      (event) => {
        logger.log("Event data: ", event.data.message);
      }
    );
    
  • 切换部署区域
    若当前区域(us-central1)资源配额紧张,可以尝试切换到其他区域部署。修改firebase.json中的functions区域配置:

    {
      "functions": {
        "source": "functions",
        "region": "europe-west1"
      }
    }
    
  • 检查并调整配额
    确认项目在目标区域的Cloud Run CPU配额是否满足需求,若长期需要更高的扩缩容上限,可申请提升对应区域的配额。

内容的提问来源于stack exchange,提问作者Danh Đào Thanh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 11:44:55