Search code examples
node.jsazureazure-functionsazure-eventgrid

Azure Function with Event Grid run local without ngrok


I have an app that uses AzureFunction and EventGrid with Nodejs. I want to debug some Event Trigger Functions in localhost, but I don't want to use Ngrok, for particular reasons. There is another way to achieve EventGrid debugging without Ngrok?


Solution

  • When running Azure function locally, the EventGridTrigger can be access through this url:

    http://localhost:7071/runtime/webhooks/EventGrid?functionName={functionname}
    

    From Postman (for example), you would need these additional headers:

    • Content-Type: application/json
    • aeg-event-type: Notification

    A full http request would looks like this

    POST /runtime/webhooks/EventGrid?functionName={functionname}
    Host: http://localhost:7071
    Content-Type: application/json
    aeg-event-type: Notification
    
    {
      "topic": "/subscriptions/5b4b650e-28b9-4790-b3ab-ddbd88d727c4/resourcegroups/test/providers/Microsoft.EventHub/namespaces/test",
      "subject": "eventhubs/test",
      "eventType": "captureFileCreated",
      "eventTime": "2017-07-14T23:10:27.7689666Z",
      "id": "7b11c4ce-1c34-4416-848b-1730e766f126",
      "data": {
        "fileUrl": "https://test.blob.core.windows.net/debugging/testblob.txt",
        "fileType": "AzureBlockBlob",
        "partitionId": "1",
        "sizeInBytes": 0,
        "eventCount": 0,
        "firstSequenceNumber": -1,
        "lastSequenceNumber": -1,
        "firstEnqueueTime": "0001-01-01T00:00:00",
        "lastEnqueueTime": "0001-01-01T00:00:00"
      },
      "dataVersion": "",
      "metadataVersion": "1"
    }
    
    

    Calling Azure Function EventgridTrigger from Postman

    VS Code debug - Azure Function EventgridTrigger