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

Firebase Python函数如何配置region、timeout及memory参数?

Firebase Python 函数等效配置写法(对应TS/JS内联配置)

在TypeScript/JavaScript中,我们可以这样内联配置Firebase函数的区域、超时和内存:

import * as functions from "firebase-functions";

export const fooFunction = functions
  .runWith({
    timeoutSeconds: 60,
    memory: "512MB",
  })
  .region("us-central1")
  .https.onCall((data, context) => {
     // 函数逻辑
});

对应到Python Firebase SDK中,你可以直接通过@https_fn.on_call装饰器的参数来设置这些配置,以下是等效写法:

from firebase_functions import https_fn
from firebase_functions.options import MemoryOption

@https_fn.on_call(
    region="us-central1",
    timeout_sec=60,
    memory=MemoryOption.MB_512
)
def foo_function(req: https_fn.CallableRequest) -> https_fn.Response:
    # 函数逻辑
    return https_fn.Response("处理完成")

参数说明:

  • region:直接传入装饰器参数,指定函数部署的云区域,和TS中的.region()方法作用一致。
  • timeout_sec:设置函数的最大运行超时时间,单位为秒,对应TS里的timeoutSeconds。
  • memory:可以使用MemoryOption枚举类的预设值(如MB_512),也可以直接传入字符串格式的内存值(如"512MiB"),对应TS中的memory配置。

内容的提问来源于stack exchange,提问作者Boern

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 13:02:06