1
votes

I want to be able to dynamically read the blob file (json) with Azure Function Python with the filename passed through Azure Event hub message. How can I do that with Azure Bindings?

function.json

{
    "scriptFile": "__init__.py",
    "bindings": [
        {
            "type": "eventHubTrigger",
            "name": "events",
            "direction": "in",
            "eventHubName": "beta-api-intergration",
            "connection": "receiverConnectionString",
            "cardinality": "many",
            "consumerGroup": "beta-api-consumer",
            "dataType": "binary"
        },
        {
            "name": "betablob",
            "type": "blob",
            "path": "swuploads/{filename}.json",
            "connection": "AzureWebJobsStorage",
            "direction": "in"
        }
    ]
}

init.py

def main(events: List[func.EventHubEvent], betablob: func.InputStream):
    well.login(user,pwd)
    for event in events:
        logging.info('Python EventHub trigger processed an event: %s', event.get_body().decode('utf-8'))

        ###msg contains the file name I want to load in blob
        msg=parse_msg(event) 
        ####how do I pass the file name here ?
        data=load_blob(betablob) 
1
Here is an example for something similar with Service Bus triggers. Maybe you can try to adopt that for Event Hubs docs.microsoft.com/en-us/azure/azure-functions/…silent
@silent I tried looking into that but it appears that it doesn't allow the input bindings to be tied to the function itself.chad
@chadleong maybe the easiest way to goal this its read filename from event and write load_blob function and pass to this function filename as string that loads blob via blob_client ?Anton Komyshan
@AntonKomyshan I was hoping to achieve this with pure bindings without using the blob client SDK, I guess that's my only option ?chad
I took a look at the event hub and it seems that the specified type of information cannot be passed in, so it is impossible to achieve dynamics with pure binding. You need the Python-based Azure SDK to achieve your needs.1_1

1 Answers

1
votes

Under normal circumstances, dynamic binding can be realized indirectly by passing in json format input (or trigger).

For example, send message like this:

{
   "filename":"test"
}

And then binding will get the value 'test'.(This only works for language like python which use declarative bindings.)

But it seems that event hub cannot specify the format of the incoming information, so pure binding cannot be achieved. You need the python-based Azure SDK to implement dynamic binding.