有没有办法使用PowerShell命令运行Azure Function?
Start-AzFunctionApp -Name "function-name" -ResourceGroupName "resource-group-name" 这会启动该函数,但我没有看到任何运行该函数的命令。
我已使用此命令
Invoke-RestMethod -Method 'Post' -Uri "<function url>"
在我的函数应用程序中执行 Http 触发器。
我创建了一个名为
HttpTrigger1
的 python 函数,运行 PowerShell 命令来执行该函数。
我使用了 HTTP 触发器的默认示例代码。我的代码。
__init__.py
:
import logging
import azure.functions as func
def main(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
)
运行 PowerShell 命令
Invoke-RestMethod -Method 'Post' -Uri "<function url>"
Output
:
我已使用
?name=Vivek
传递 name
的值。