如何在部署Python Gen2时更改云函数参数?

huangapple go评论67阅读模式
英文:

How to change cloud function parameters when deploying python gen2?

问题

I am writing Firebase Cloud Function in python using the new "Firebase way".

I would like to be able to set the region and memory for the function when I deploy them, in Node JS this is easy:

from firebase_functions import https_fn
from firebase_admin import initialize_app

initialize_app()

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

@https_fn.on_request()
def example(req: https_fn.CallableRequest) -> https_fn.Response:
    logging.info(f"Request example called : {req.auth}")
    return https_fn.Response("Hello world!")

EDIT:

I have found the set_global_options() method by playing around and guessing from NodeJS.

However, I still need the answer to set the options.HttpsOptions parameters for each function inside @https_fn.on_call(options=HttpsOptions(something...))

英文:

I am writing Firebase Cloud Function in python using the new "Firebase way".

I would like to be able to set the region and memory for the function when i deploy them, in Node JS this is easy :

setGlobalOptions({ region: "asia-northeast1" });

exports.date = onRequest({
    // set concurrency value
    concurrency: 500
  },
  (req, res) => {
    // ...
});

How to do the same in python :

from firebase_functions import https_fn
from firebase_admin import initialize_app

initialize_app()

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


@https_fn.on_request()
def example(req: https_fn.CallableRequest) -> https_fn.Response:
    logging.info(f"Request example called : {req.auth}")
    return https_fn.Response("Hello world!")

EDIT :

I have found the set_global_options() method by playing around and guessing from NodeJS.

However, i still need the answer to set the options.HttpsOptions parameters for each function inside @https_fn.on_call(options=HttpsOptions(something...))

答案1

得分: 1

以下是已翻译的内容:

Firebase Functions 中可以为 on_call()on_request() 函数设置诸如区域、内存和超时等参数,这些参数可以作为 **kwargs 设置,详情请参阅文档。可能的参数及其名称与 HttpsOptions 相似。

设置区域、内存和超时的自定义值示例:

from firebase_functions import https_fn
from firebase_admin import initialize_app

initialize_app()

@https_fn.on_request(region="europe-west3", memory=512, timeout_sec=90)
def example(req: https_fn.CallableRequest) -> https_fn.Response:
    return https_fn.Response("Hello world!")
英文:

Parameters like region, memory, and timeout for Firebase Functions can be set for on_call() and on_request() functions as **kwargs, for details see the documentation. Possible parameters and their names are analog to HttpsOptions.

Example for setting custom values for region, memory, and timeout:

from firebase_functions import https_fn
from firebase_admin import initialize_app

initialize_app()


@https_fn.on_request(region="europe-west3", memory=512, timeout_sec=90)
def example(req: https_fn.CallableRequest) -> https_fn.Response:
    return https_fn.Response("Hello world!")

huangapple
  • 本文由 发表于 2023年5月25日 20:30:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76332293.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定