简体   繁体   English

创建 blob 时如何在 azure 中触发事件触发的 function

[英]How to trigger an event-triggered function in azure when a blob is create

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: 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:这是我的 init.py 文件:

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.现在,我想在上传 blob 时触发这个 function。 So I went to my storage account, pressed on "Events" and chose "Azure Function".所以我去了我的存储帐户,按下“事件”并选择“Azure 功能”。 在此处输入图像描述 and create.并创造。

Next I chose the function app and the function I just created接下来我选择了我刚刚创建的 function 应用程序和 function

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.但这就是我所看到的,我不明白接下来要做什么,以及在我上传 blob 后如何让这个 function 着火。

在此处输入图像描述

Any help will be appreciated!任何帮助将不胜感激!

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:我遵循了这个解决方法:您可以在使用 azure 函数时使用Microsoft.Storage.BlobCreated ,如下所示:

在此处输入图像描述

Click on Azure functions in end point type then click on end point as below:点击端点类型中的 Azure 功能,然后点击端点如下:

在此处输入图像描述

Upload a blob like below:上传如下 Blob:

在此处输入图像描述

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:上传 blob 后,检查事件网格 function 应用程序的日志如下,您将知道它已执行并且事件网格被触发如下:

在此处输入图像描述

You can use Logics apps for triggering an event when a blob is created as below:您可以使用逻辑应用程序在创建 blob 时触发事件,如下所示:

在此处输入图像描述

And when i upload a blob like below it runs and gets triggered as below:当我上传一个像下面这样的 blob 时,它会运行并触发如下:

在此处输入图像描述

Now when you check the run history it trigered as below:现在,当您检查运行历史记录时,它会触发如下:

在此处输入图像描述

And you can check as below:您可以检查如下:

在此处输入图像描述

So, in last you can check the events i created as below:因此,最后您可以检查我创建的事件,如下所示:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM