Home > Software engineering >  How to trigger an event-triggered function in azure when a blob is create
How to trigger an event-triggered function in azure when a blob is create

Time:09-14

I created an event-triggered function in Azure (name of the function app: "stamevents", name of the function: "EventGridTrigger1". this is my function.json file:

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "event",
      "direction": "in"
    }
  ]
}

and this is my init.py file:

import json
import logging

import azure.functions as func


def main(event: func.EventGridEvent):
    result = json.dumps({
        'id': event.id,
        'data': event.get_json(),
        'topic': event.topic,
        'subject': event.subject,
        'event_type': event.event_type,
    })

    logging.info('Python EventGrid trigger processed an event: %s', result)

Now, I want to trigger this function when I'm uploading a blob. So I went to my storage account, pressed on "Events" and chose "Azure Function". enter image description here and create.

Next I chose the function app and the function I just created

But this is what I see and I don't understand what to do next, and how to make this function fire after I upload a blob.

enter image description here

Any help will be appreciated!

CodePudding user response:

I have reproduced in my environment and i got expected results. I followed this workaround: You can use Microsoft.Storage.BlobCreated as below in using azure functions:

enter image description here

Click on Azure functions in end point type then click on end point as below:

enter image description here

Upload a blob like below:

enter image description here

After uploading blob check the logs of event grid function app as below, you will get to know it has executed and event grid got triggered as below:

enter image description here

You can use Logics apps for triggering an event when a blob is created as below:

enter image description here

And when i upload a blob like below it runs and gets triggered as below:

enter image description here

Now when you check the run history it trigered as below:

enter image description here

And you can check as below:

enter image description here

So, in last you can check the events i created as below:

enter image description here

  • Related