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

部署Python版第二代Firebase云函数时如何配置参数?

Python版Firebase Cloud Function配置region与memory参数

一、全局配置(所有函数默认生效)

使用set_global_options方法可统一设置所有云函数的默认参数,比如区域、内存规格:

from firebase_functions import https_fn, options
from firebase_admin import initialize_app
import logging

# 全局配置:设置默认区域为asia-northeast1,内存为512MB
options.set_global_options(
    region="asia-northeast1",
    memory=options.MemoryOption.MB_512
)

initialize_app()
logging.getLogger("Functions").setLevel(logging.INFO)

二、单个函数独立配置(覆盖全局设置)

如果需要给特定函数单独指定参数,直接在on_request或on_call装饰器中传入options参数,实例化HttpsOptions即可,支持配置region、memory、concurrency等属性:

针对HTTP触发函数(on_request)

@https_fn.on_request(
    options=https_fn.HttpsOptions(
        region="us-central1",  # 单独设置该函数的区域
        memory=options.MemoryOption.MB_1024,  # 单独设置内存为1GB
        concurrency=500  # 设置该函数的最大并发数
    )
)
def example(req: https_fn.Request) -> https_fn.Response:
    logging.info(f"Request example called : {req.auth}")
    return https_fn.Response("Hello world!")

针对Callable触发函数(on_call)

@https_fn.on_call(
    options=https_fn.HttpsOptions(
        region="asia-northeast1",
        memory=options.MemoryOption.MB_256,
        concurrency=300
    )
)
def callable_example(req: https_fn.CallableRequest) -> dict:
    return {"message": "Hello from callable function!"}

参数说明

  • region:支持Firebase云函数的所有可用区域,比如asia-northeast1、us-central1等;
  • memory:通过options.MemoryOption枚举选择,可选值包括MB_128、MB_256、GB_1、GB_2等;
  • concurrency:设置函数的最大并发执行数量。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.20 21:32:30