Azure Function not triggering when deployed, but works correctly in local debugging

Thermalog 0 Reputation points
2023-04-15T06:04:15.2266667+00:00

I have an Azure Function that is triggered by an Event Hub and pushes data to a PostgreSQL database. The function works correctly when debugging in Visual Studio Code, and I can see the data being pushed to the database. However, when I deploy the function to Azure, it does not trigger as expected. The moment I start debugging in Visual Studio Code, the data starts being added to the database again. When I used to look at the Monitor tab inside the Azure Functions portal, I could see invocation traces with success count and error count, as well as logs. Now, I can still see the logs but not the invocation traces with success count and error counts. I have checked the logs, and it seems to be related to an issue with invocation: yamlCopy code

2023-04-15T05:03:23Z   [Information]   Executing 'Functions.EventHubTrigger' (Reason='(null)', Id=f56046a2-5c28-4997-a425-de7484ee5630)
2023-04-15T05:03:23Z   [Information]   Trigger Details: PartionId: 1, Offset: 4295425312-4295426024, EnqueueTimeUtc: 2023-04-15T05:02:06.6860000+00:00-2023-04-15T05:02:28.8280000+00:00, SequenceNumber: 1437-1438, Count: 2
2023-04-15T05:03:23Z   [Verbose]   Sending invocation id:f56046a2-5c28-4997-a425-de7484ee5630
2023-04-15T05:03:23Z   [Verbose]   Posting invocation id:f56046a2-5c28-4997-a425-de7484ee5630 on workerId:76c4899c-85c0-494d-9f5b-114136c88ecc
2023-04-15T05:03:23Z   [Error]   Executed 'Functions.EventHubTrigger' (Failed, Id=f56046a2-5c28-4997-a425-de7484ee5630, Duration=27ms)

I have verified that the data from the Android app is being published correctly, and the issue seems to be with the function triggering when deployed. Please help me identify the root cause of this issue and suggest how to fix it so that the function triggers correctly when deployed to Azure.

Azure SQL Database
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Boris Von Dahle 3,221 Reputation points
    2023-04-15T06:32:13.5466667+00:00

    Based on the information you provided, it's not clear what's causing the issue with your Azure Function. However, there are a few things you can check and try to resolve the problem: Check the connection string: Verify that the connection string for the Event Hub trigger in the local.settings.json file and the connection string in the Azure Function App settings are identical (except for the "Endpoint" part). Make sure that the connection string in the Azure Function App settings is using the correct Event Hub namespace and Event Hub name. Check the function.json file: Ensure that your function.json file has the correct configuration for the Event Hub trigger binding. Verify the type, name, direction, eventHubName, and connection properties. For example:

    {
      "bindings": [
        {
          "type": "eventHubTrigger",
          "name": "input",
          "direction": "in",
          "eventHubName": "your-eventhub-name",
          "connection": "EventHubConnectionString",
          "cardinality": "many",
          "dataType": "binary"
        }
      ]
    }
    
    

    Deploy again: Sometimes, the deployment may not be successful or may have issues. Try redeploying your Azure Function App and see if that resolves the issue. Hope this helps.


  2. Oury Ba-MSFT 21,126 Reputation points Microsoft Employee Moderator
    2023-04-18T23:28:18.3166667+00:00

    @Thermalog Thank you for reaching out and sorry to hear about this issue. My understanding is that your function is not triggering by an Azure event hub when deploy in Azure but works locally. After looking a the below functions setting you shared above. The EventHub trigger will have a connection string setting. Depending on the language that is either on the method attribute or in the Function.json. You can try to configure the connectionstring name that is created in local.settings.json. This setting needs to be also added to the Function App Settings after deployment for the code to Trigger.  The value of connection is the name of an app setting that contains the connection string, not the connection string itself. Bindings use connection strings stored in app settings to enforce the best practice that function.json does not contain service secrets. Azure Functions trigger and binding example | Microsoft Learn Quickstart: Create an event hub using Azure portal Please do comment below if the issue persists. Regards, Oury


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.