我正在尝试将 2 个函数发布到我的 Azure 函数应用程序“copy-read-from-esb”。
一切都是在 VS Code 中用 Python 编写的。问题是,如果 Python 文件的名称是
function_app.py
,它看起来只会在我的函数应用程序中注册。但由于我有 2 个,它们不能具有相同的名称,并且不名为 function_app.py
的名称将不会在我的函数应用程序中注册。
看起来 Azure 函数使用
function.json
文件,但我不确定这是如何工作的,也不知道这是否仅适用于 C#。
我尝试通过 CLI 进行发布
func azure functionapp publish ..
,虽然这似乎可行,但我只能添加一个 .py
文件,因为所需的命名约定以某种方式设置为 function__app.py
。
您需要在同一个
function_app.py
文件中添加这两个函数,或者您可以创建一个 blueprint file
并从那里调用所有函数触发器。
参考我的 SO answer1 在
function_app.py
和 SO answer2 中运行 2 个函数以实现 蓝图实现。
我创建了 2 个函数并将它们添加到 function_app.py 中:-
function_app.py:-
import azure.functions as func
import logging
app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.route(route="http_trigger")
def http_trigger(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
name = req.params.get('name')
if not name:
try:
req_body = req.get_json()
except ValueError:
pass
else:
name = req_body.get('name')
if name:
return func.HttpResponse(f"Hello, {name}. This HTTP triggered function executed successfully.")
else:
return func.HttpResponse(
"This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.",
status_code=200
)
@app.timer_trigger(schedule="0 * * * * *", arg_name="myTimer", run_on_startup=True,
use_monitor=False)
def timer_trigger(myTimer: func.TimerRequest) -> None:
if myTimer.past_due:
logging.info('The timer is past due!')
logging.info('Python timer trigger function executed.')
通过 CLI 部署功能的命令:-
az login
az account set --subscription "SubscriptionName"
func azure functionapp publish siliconfunc5
输出:-
两个功能触发器均已使用上面的功能核心工具命令成功部署。