添加EventHubTrigger后Azure Functions全部消失问题求助
问题描述
使用Azure学生套餐的弹性消耗计划开发时遇到以下问题:
- 仅添加默认httpTrigger时,函数可正常被识别并运行;
- 一旦添加eventHubTrigger,所有函数(包括原本正常的httpTrigger)都会从Azure平台中消失;
- 该问题已在两个不同的Function App中复现;
- GitHub Actions能完成代码部署,文件已成功上传,但Azure始终不将其识别为有效Python函数;
- 未改动文件/文件夹结构,默认文件未修改,requirements.txt已同步更新依赖;
- 已尝试多种排查方法,包括咨询AI工具,问题仍未解决。
函数代码(function_app.py)
import azure.functions as func import logging import json import os import uuid from azure.cosmos import CosmosClient app = func.FunctionApp(http_auth_level=func.AuthLevel.ANONYMOUS) @app.route(route="http_trigger") def http_trigger(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 ) @app.event_hub_message_trigger( arg_name="azeventhub", event_hub_name="iothub-ehub-applied-io-55753535-0fd7cb3e46", connection="IOTHUB" ) def eventhub_trigger1(azeventhub: func.EventHubEvent): logging.info('Python EventHub trigger processed an event.') # Initialize Cosmos inside the function so it only runs when triggered cosmos_client = CosmosClient( os.getenv("COSMOS_URL"), credential=os.getenv("COSMOS_KEY") ) container = cosmos_client \ .get_database_client(os.getenv("COSMOS_DB_NAME")) \ .get_container_client(os.getenv("COSMOS_CONTAINER_NAME")) try: # 1. Decode message body = azeventhub.get_body().decode('utf-8') logging.info(f"Raw message: {body}") data = json.loads(body) # 2. Check if OPCUA data exists if "OPCUA" in data: opcua_data = data["OPCUA"] # 3. Prepare item for Cosmos DB item = { "id": str(uuid.uuid4()), "type": "OPCUA", **opcua_data } # 4. Insert into Cosmos DB container.create_item(body=item) logging.info(f"Inserted OPCUA data: {item}") else: logging.warning("Message is not OPCUA, skipping") except Exception as e: logging.error(f"Error processing event: {e}")
Azure平台日志
2026-05-05T12:12:12 [Information] Executing StatusCodeResult, setting HTTP status code 200 2026-05-05T12:12:33 [Verbose] Ping Status: { "hostState": "Running" } 2026-05-05T12:12:33 [Information] Executing StatusCodeResult, setting HTTP status code 200 2026-05-05T12:12:34 [Verbose] AuthenticationScheme: WebJobsAuthLevel was not authenticated. 2026-05-05T12:12:34 [Verbose] Authorization was successful. 2026-05-05T12:12:34 [Verbose] Received request to drain the host 2026-05-05T12:12:34 [Information] DrainMode mode enabled 2026-05-05T12:12:34 [Information] Calling StopAsync on the registered listeners 2026-05-05T12:12:34 [Information] Call to StopAsync complete, registered listeners are now stopped 2026-05-05T12:12:34 [Verbose] AuthenticationScheme: WebJobsAuthLevel was not authenticated. 2026-05-05T12:12:34 [Verbose] Authorization was successful. 2026-05-05T12:12:34 [Verbose] Received request to drain the host 2026-05-05T12:12:34 [Information] DrainMode mode enabled 2026-05-05T12:12:34 [Information] Calling StopAsync on the registered listeners 2026-05-05T12:12:34 [Information] Call to StopAsync complete, registered listeners are now stopped 2026-05-05T12:12:38 [Verbose] Ping Status: { "hostState": "Running" } 2026-05-05T12:12:38 [Information] Executing StatusCodeResult, setting HTTP status code 200 2026-05-05T12:12:40 [Verbose] AuthenticationScheme: WebJobsAuthLevel was not authenticated. 2026-05-05T12:12:40 [Verbose] Authorization was successful. 2026-05-05T12:12:40 [Verbose] Drain Status: 2, Activity Status: { "OutstandingInvocations": 0, "OutstandingRetries": 0 } 2026-05-05T12:12:40 [Verbose] AuthenticationScheme: WebJobsAuthLevel was not authenticated. 2026-05-05T12:12:40 [Verbose] Authorization was successful. 2026-05-05T12:12:40 [Verbose] Drain Status: 2, Activity Status: { "OutstandingInvocations": 0, "OutstandingRetries": 0 } 2026-05-05T12:12:42 [Verbose] Ping Status: { "hostState": "Running" } 2026-05-05T12:12:42 [Information] Executing StatusCodeResult, setting HTTP status code 200 2026-05-05T12:13:03 [Verbose] Ping Status: { "hostState": "Running"
内容的提问来源于stack exchange,提问作者GewoonTijn7
相关产品推荐
相关产品推荐

