英文:
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 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
Works locally
答案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:
- 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
- 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.
-
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>
:
Portal:
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:
Portal:
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:
- Make sure you added the setting
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing"
inlocal.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
- 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.
-
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>
:
Portal:
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:
Portal:
References:
Create a Python function from the command line
You can also refer GitHub ticket raised on the same issue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论