英文:
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!")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论