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

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

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:

  1. from firebase_functions import https_fn
  2. from firebase_admin import initialize_app
  3. initialize_app()
  4. logging.getLogger("Functions").setLevel(logging.INFO)
  5. @https_fn.on_request()
  6. def example(req: https_fn.CallableRequest) -> https_fn.Response:
  7. logging.info(f"Request example called : {req.auth}")
  8. 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 :

  1. setGlobalOptions({ region: "asia-northeast1" });
  2. exports.date = onRequest({
  3. // set concurrency value
  4. concurrency: 500
  5. },
  6. (req, res) => {
  7. // ...
  8. });

How to do the same in python :

  1. from firebase_functions import https_fn
  2. from firebase_admin import initialize_app
  3. initialize_app()
  4. logging.getLogger("Functions").setLevel(logging.INFO)
  5. @https_fn.on_request()
  6. def example(req: https_fn.CallableRequest) -> https_fn.Response:
  7. logging.info(f"Request example called : {req.auth}")
  8. 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 相似。

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

  1. from firebase_functions import https_fn
  2. from firebase_admin import initialize_app
  3. initialize_app()
  4. @https_fn.on_request(region="europe-west3", memory=512, timeout_sec=90)
  5. def example(req: https_fn.CallableRequest) -> https_fn.Response:
  6. 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:

  1. from firebase_functions import https_fn
  2. from firebase_admin import initialize_app
  3. initialize_app()
  4. @https_fn.on_request(region="europe-west3", memory=512, timeout_sec=90)
  5. def example(req: https_fn.CallableRequest) -> https_fn.Response:
  6. 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:

确定