通过Powershell命令运行Azure Function

问题描述 投票:0回答:1

有没有办法使用PowerShell命令运行Azure Function?

Start-AzFunctionApp -Name "function-name" -ResourceGroupName "resource-group-name" 这会启动该函数,但我没有看到任何运行该函数的命令。

azure azure-functions azure-powershell azure-durable-functions
1个回答
0
投票

我已使用此命令

Invoke-RestMethod -Method 'Post' -Uri "<function url>"
在我的函数应用程序中执行 Http 触发器。

我创建了一个名为

HttpTrigger1
的 python 函数,运行 PowerShell 命令来执行该函数。

enter image description here

enter image description here

我使用了 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
的值。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.