Here are the steps to create function app that triggers when there is an event generated in EventHub try to check these steps and make required changes in your code to execute your requirement.
Add the below code in your local.settings.json
file z
{
"IsEncrypted": false,
"Values": {
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsStorage": [Paste the Storage account connection string which is linked with your Azure function that you have Created on Azure Portal],
"FUNCTIONS_EXTENSION_VERSION": "~2",
"receiverConnectionString": [Paste the Endpoint Connection String of the EventHubNamespace here in double quotes and remove these brackets.],
"MyStorageConnectionString": [Paste the Endpoint Connection String of the blob storage account here in double quotes and remove these brackets.]
},
"ConnectionStrings": {}
}
Below is the code that will bind azure function with EventHub so that it will result in triggering message automatically when there is any event generated in EventHub.
{
"scriptFile": "__init__.py",
"bindings": [{
"type": "eventHubTrigger",
"name": "events",
"direction": "in",
"eventHubName": [Enter the name of your event hub in double quotes and remove these brackets.],
"connection": "receiverConnectionString",
"cardinality": "many","consumerGroup": "$Default",
"dataType": "binary"
},
{
"name": "outputblob",
"type": "blob",
"path": [Enter the path of the folder where you want to store the data in double quotes and remove these brackets.],
"connection": "MyStorageConnectionString",
"direction": "out"
}]
}
For Complete information check Azure Functions and EventHub.
Also, Check these SO threads for related information. SO1, SO2 and these Microsoft Q&A