Azure Event Hub触发的Zip部署Function App触发异常求助
Looks like you're hitting a common issue where your Event Hub-triggered Function only runs when you debug it in the Azure Portal, and stops triggering after about 15 minutes. Let's break down the likely causes and fixes based on your Terraform config:
1. Consumption Plan Idle Timeout (Most Likely Culprit)
Your Terraform config references an azurerm_app_service_plan.helloworld but doesn't specify its SKU. If you're using a Consumption Plan (the default for many Function App setups), it has a built-in idle timeout: after 15 minutes of inactivity, the Function App goes into a cold state. In this state, the Event Hub listener shuts down, and won't automatically wake up until a manual trigger (like portal debugging) kicks it off again.
Fix:
- If you need continuous listening, switch to a Dedicated (App Service) Plan or Elastic Premium Plan and enable the
Always Onsetting in your Function App. Add this to yourapp_settingsblock in Terraform:
Note:app_settings { # ... existing settings ... WEBSITE_ALWAYS_ON = "1" }Always Onisn't supported for Consumption Plans, so you'll need to update your App Service Plan SKU to something likeS1(Dedicated) orEP1(Elastic Premium).
2. Zip Deployment Trigger Registration Issues
You're using WEBSITE_USE_ZIP to deploy from a blob storage SAS URL. Sometimes, if the deployment doesn't trigger a full reload of the Function App, the Event Hub listener might not register properly after the initial deployment (only waking up when you manually trigger a debug session).
Fixes:
- Replace
WEBSITE_USE_ZIPwithWEBSITE_RUN_FROM_PACKAGE(recommended for modern Zip deployments). This ensures the Function App runs directly from the package and properly scans for triggers on startup. Update your app setting:app_settings { # Replace WEBSITE_USE_ZIP with this: WEBSITE_RUN_FROM_PACKAGE = "${azurerm_storage_blob.helloworld.url}${data.azurerm_storage_account_sas.helloworld.sas}" # ... existing settings ... } - Ensure your
HASHvalue changes with every deployment. If the SHA256 hash stays the same, the Function App might skip reloading the package, leading to stale trigger configurations. Double-check thatdata.archive_file.helloworldis correctly generating a new hash when your function code changes.
3. Verify Event Hub Trigger Configuration
Your setup uses the connection string with EntityPath and leaves eventHubName empty in function.json—that's the correct approach, but let's confirm a few details:
- Make sure the Event Hub authorization rule (
azurerm_eventhub_authorization_rule.helloworld) has Listen permissions (at minimum) for the Function App to read from the Event Hub. - Check that your function is using a unique consumer group (not just
$Default) if there are other consumers reading from the same Event Hub. A consumer group can only have one active listener per partition, which might cause conflicts if another service is using the same group.
4. Check Function App Logs for Clues
To get more details on why the trigger stops, enable Application Insights for your Function App and check the logs:
- Look for messages about the Event Hub listener shutting down due to inactivity.
- Check for errors related to connection issues or permission failures that might only occur after the initial debug session.
内容的提问来源于stack exchange,提问作者StephenG

