Azure Function v2 Python部署的函数未显示。

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

Azure Function v2 Python deployed functions are not showing

问题

Locally the functions debug just fine, if I deploy via vscode to my azure function I get No HTTP Triggers found and the devops pipeline does not deploy triggers either.

我在本地调试这些函数时一切正常,但如果我通过VSCode部署到Azure函数,我会收到“未找到HTTP触发器”的消息,而DevOps管道也不会部署触发器。

I have "AzureWebJobsFeatureFlags": "EnableWorkerIndexing" set locally and as a function app setting.

我在本地和函数应用设置中都设置了"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"。

Code is appropriately decorated

代码已经适当地进行了装饰

@app.route(route="functionname", auth_level=func.AuthLevel.FUNCTION)
def functioname(req: func.HttpRequest) -> func.HttpResponse:

@app.route(route="functionname", auth_level=func.AuthLevel.FUNCTION)
def functioname(req: func.HttpRequest) -> func.HttpResponse:

Deployments succeed both ways but no functions show

部署都成功了,但没有显示任何函数

Azure Pipeline shows correct files:

Azure管道显示了正确的文件:

Azure function app files show function_app.py at the root folder

Azure函数应用文件在根文件夹中显示function_app.py

test function

测试函数

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.function_name("personas")
@app.route(route="character-managment/personas")
def personas(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
return func.HttpResponse("ok", status_code=200)

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)
@app.function_name("personas")
@app.route(route="character-managment/personas")
def personas(req: func.HttpRequest) -> func.HttpResponse:
logging.info('Python HTTP trigger function processed a request.')
return func.HttpResponse("ok", status_code=200)

Folder structure

文件夹结构

Works locally

在本地运行正常

英文:

Locally the functions debug just fine, if I deploy via vscode to my azure function I get No HTTP Triggers found and the devops pipeline does not deploy triggers either.

I have "AzureWebJobsFeatureFlags": "EnableWorkerIndexing" set locally and as a function app setting.

Code is appropriately decorated

@app.route(route="functionname", auth_level=func.AuthLevel.FUNCTION)
def functioname(req: func.HttpRequest) -> func.HttpResponse:

Deployments succeed both ways but no functions show

Azure Pipeline shows correct files:
Azure Function v2 Python部署的函数未显示。

Azure function app files show function_app.py at the root folder

test function

app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS)    
@app.function_name("personas")
    @app.route(route="character-managment/personas")
    def personas(req: func.HttpRequest) -> func.HttpResponse:
        logging.info('Python HTTP trigger function processed a request.')
    return func.HttpResponse("ok", status_code=200)

Folder structure

Azure Function v2 Python部署的函数未显示。

Works locally

Azure Function v2 Python部署的函数未显示。

答案1

得分: 0

I tried to reproduce the same in my environment. I could see the deployed function in Azure function app.

  • Created a test default Python v2 function and deployed to Azure function app.

Local:

Azure Function v2 Python部署的函数未显示。

  • Make sure you added the setting "AzureWebJobsFeatureFlags": "EnableWorkerIndexing" in local.settings.json:
{
  "IsEncrypted": false,
  "Values": {
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
    "AzureWebJobsStorage": "<storage_connection_string>"
  }
}
  • Create and activate a new virtual environment using the commands:
py -m venv .venv
. \.venv\Scripts\activate

Azure Function v2 Python部署的函数未显示。

  • Include all the required packages in requirements.txt file.
  • Install all the packages by running the command pip run -r requirements.txt in the terminal.

Azure Function v2 Python部署的函数未显示。

  • Created a Python function app with Consumption plan and version 3.10.

  • Deployed the function with the command func azure functionapp publish <function_app_name>:

Azure Function v2 Python部署的函数未显示。

Azure Function v2 Python部署的函数未显示。

Portal:

Azure Function v2 Python部署的函数未显示。

Azure Function v2 Python部署的函数未显示。

I could also deploy the function with custom packages to Azure Function App.

requirements.txt:

azure-functions
numpy
pandas

Code(function_app.py):

import azure.functions as func
import logging
import numpy as np
import pandas as pd
app = func.FunctionApp()


@app.route(route="HttpTrigger", auth_level=func.AuthLevel.ANONYMOUS)
def HttpTrigger(req: func.HttpRequest) -> func.HttpResponse:
    logging.info('Python HTTP trigger function processed a request.')

    arr = np.array([1, 2, 3])
    df = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6]})

    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 with {arr} and {df}.")
    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
        )

Local:

Azure Function v2 Python部署的函数未显示。

Azure Function v2 Python部署的函数未显示。
Azure Function v2 Python部署的函数未显示。

Portal:

Azure Function v2 Python部署的函数未显示。

Azure Function v2 Python部署的函数未显示。

References:

Create a Python function from the command line

You can also refer GitHub ticket raised on the same issue.

英文:

I tried to reproduce the same in my environment. I could see the deployed function in Azure function app.

  • Created a test default Python v2 function and deployed to Azure function app.

Local:

Azure Function v2 Python部署的函数未显示。

  • Make sure you added the setting &quot;AzureWebJobsFeatureFlags&quot;: &quot;EnableWorkerIndexing&quot; in local.settings.json:
{
  &quot;IsEncrypted&quot;: false,
  &quot;Values&quot;: {
    &quot;FUNCTIONS_WORKER_RUNTIME&quot;: &quot;python&quot;,
    &quot;AzureWebJobsFeatureFlags&quot;: &quot;EnableWorkerIndexing&quot;,
    &quot;AzureWebJobsStorage&quot;: &quot;&lt;storage_connection_string&gt;&quot;
  }
}
  • Create and activate a new virtual environment using the commands:
py -m venv .venv
. \.venv\Scripts\activate

Azure Function v2 Python部署的函数未显示。

  • Include all the required packages in requirements.txt file.
  • Install all the packages by running the command
    pip run -r requirements.txt in the terminal.

Azure Function v2 Python部署的函数未显示。

  • Created a Python function app with Consumption plan and version 3.10.

  • Deployed the function with the command func azure functionapp publish &lt;function_app_name&gt;:

Azure Function v2 Python部署的函数未显示。

Azure Function v2 Python部署的函数未显示。

Portal:

Azure Function v2 Python部署的函数未显示。

Azure Function v2 Python部署的函数未显示。


I could also deploy the function with custom packages to Azure Function App.

requirements.txt:

azure-functions
numpy
pandas

Code(function_app.py):

import azure.functions as func
import logging
import numpy as np
import pandas as pd
app = func.FunctionApp()


@app.route(route=&quot;HttpTrigger&quot;, auth_level=func.AuthLevel.ANONYMOUS)
def HttpTrigger(req: func.HttpRequest) -&gt; func.HttpResponse:
    logging.info(&#39;Python HTTP trigger function processed a request.&#39;)

    arr = np.array([1, 2, 3])
    df = pd.DataFrame({&#39;A&#39;: [1, 2, 3], &#39;B&#39;: [4, 5, 6]})

    name = req.params.get(&#39;name&#39;)
    if not name:
        try:
            req_body = req.get_json()
        except ValueError:
            pass
        else:
            name = req_body.get(&#39;name&#39;)

    if name:
        return func.HttpResponse(f&quot;Hello, {name}. This HTTP triggered function executed successfully with {arr} and {df}.&quot;)
    else:
        return func.HttpResponse(
             &quot;This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response.&quot;,
             status_code=200
        )

Local:

Azure Function v2 Python部署的函数未显示。

Azure Function v2 Python部署的函数未显示。
Azure Function v2 Python部署的函数未显示。

Portal:

Azure Function v2 Python部署的函数未显示。

Azure Function v2 Python部署的函数未显示。

References:

Create a Python function from the command line

You can also refer GitHub ticket raised on the same issue.

huangapple
  • 本文由 发表于 2023年8月5日 01:02:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/76837908.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定