1

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) 
6
  • Here is an example for something similar with Service Bus triggers. Maybe you can try to adopt that for Event Hubs learn.microsoft.com/en-us/azure/azure-functions/… Commented Nov 13, 2020 at 10:16
  • @silent I tried looking into that but it appears that it doesn't allow the input bindings to be tied to the function itself. Commented Nov 13, 2020 at 10:45
  • @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 ? Commented Nov 13, 2020 at 19:48
  • @AntonKomyshan I was hoping to achieve this with pure bindings without using the blob client SDK, I guess that's my only option ? Commented Nov 13, 2020 at 22:42
  • 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. Commented Nov 18, 2020 at 7:45

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Bowman, I have resorted to using the SDK for dynamic binding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.