Azure Python V2 HTTP函数本地正常,部署后无路由映射求助
Azure Python V2函数部署后无法识别的排查问题
问题现象
- 本地调试正常,日志显示路由
api/req已映射到函数az2am - 通过Oryx远程部署成功,函数应用内文件完整,但函数未出现在函数列表中
- Application Insights报错:
Initializing function HTTP routes No HTTP routes mapped No job functions found. Try making your job classes and methods public. If you're using binding extensions (e.g. Azure Storage, ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. builder.AddAzureStorage(), builder.AddServiceBus(), builder.AddTimers(), etc.)
已尝试操作
- 配置应用设置
AzureWebJobsFeatureFlags=EnableWorkerIndexing - 切换应用计划/消耗计划,问题未解决
- 同配置的其他V2函数运行正常
本地运行日志
[2023-07-22T20:00:20.933Z] Mapped function route 'api/req' [all] to 'az2am' [2023-07-22T20:00:20.933Z] [2023-07-22T20:00:20.933Z] "RoutePrefix": "api" [2023-07-22T20:00:20.933Z] } [2023-07-22T20:00:20.942Z] Host initialized (109ms) [2023-07-22T20:00:20.944Z] Host started (120ms) [2023-07-22T20:00:20.944Z] Job host started [2023-07-22T20:00:20.949Z] Subscribed to diagnostic source 'Microsoft.Azure.WebJobs.Logging.ApplicationInsights.ApplicationInsightsLoggerProvider' Functions: az2am: http://localhost:7071/api/req
函数代码
app = func.FunctionApp() @app.function_name(name='az2am') @app.route(route='req') def main(req: func.HttpRequest) -> func.HttpResponse: useless_stuff() return func.HttpResponse(status_code=204)
host.json配置
{ "version": "2.0", "logging": { "applicationInsights": { "samplingSettings": { "isEnabled": true, "excludedTypes": "Request" } } }, "extensionBundle": { "id": "Microsoft.Azure.Functions.ExtensionBundle", "version": "[4.*, 5.0.0)" } }
排查方向
检查函数文件命名与位置
- 确保函数入口文件名为
function_app.py,这是Python V2模型的默认识别文件。若文件名不符,需在应用设置中添加FUNCTIONS_WORKER_RUNTIME_SCENARIO=Dynamic,同时设置FUNCTIONS_ENTRY_POINT指向你的函数模块。
- 确保函数入口文件名为
验证依赖安装完整性
- 确认
requirements.txt包含azure-functions>=1.17.0(V2模型最低依赖版本),部署时Oryx会根据该文件安装依赖,版本过低或缺失会导致函数索引失败。 - 查看部署日志,确认所有依赖是否安装成功,有无报错信息。
- 确认
检查运行时版本配置
- 在Azure门户函数应用的配置中,确认
FUNCTIONS_EXTENSION_VERSION设置为~4,Python V2模型仅支持v4运行时。
- 在Azure门户函数应用的配置中,确认
查看Oryx部署日志细节
- 在部署中心日志中,搜索
Detecting platforms、Building Python app等关键词,确认Oryx是否正确识别Python V2模型,有无入口文件未找到或索引失败的提示。
- 在部署中心日志中,搜索
排查代码语法/依赖缺失问题
- 检查
useless_stuff()函数是否在代码中定义,本地运行可能依赖环境中的全局定义,但部署环境中缺失会导致运行时加载失败,进而无法识别函数。
- 检查
内容的提问来源于stack exchange,提问作者holger.waschke
相关产品推荐
相关产品推荐

