简体   繁体   English

事件网格触发器 Azure 具有 Blob 存储输入和 output 的函数 Python

[英]Event Grid Trigger Azure Functions with blob storage input and output Python

I am looking for the appropriate resources/tutorials that could help me develop and deploy an Event Grid Trigger that would wait for an image upload to a blob container, process that image using python, then save the results in another blob container.我正在寻找可以帮助我开发和部署事件网格触发器的适当资源/教程,该触发器将等待图像上传到 blob 容器,使用 python 处理该图像,然后将结果保存在另一个 blob 容器中。 I have found many separate pieces of documentation which don't necessarily logically walk me through developing and deploying using the Azure Portal and VSCode, like a step-by-step walkthrough from beginning to end, of all the steps to make this possible.我发现许多单独的文档在逻辑上并不一定会引导我使用 Azure 门户和 VSCode 进行开发和部署,就像从头到尾的逐步演练一样,所有步骤使这成为可能。

Any guidance would be greatly appreciated.任何指导将不胜感激。

I don't recommand you to use Azure portal directly to develop.不建议你直接用Azure传送门来开发。 And since you need to use develop Azure function based on Python, then you need to use Azure function core tools. And since you need to use develop Azure function based on Python, then you need to use Azure function core tools.

1, Download and install Azure function core tools.(download the function3.x) 1、下载并安装Azure function核心工具。(下载function3.x)

https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash#v2 https://docs.microsoft.com/en-us/azure/azure-functions/functions-run-local?tabs=windows%2Ccsharp%2Cbash#v2

And you need to install python 3.8.x(Please notice you must download 64bit. Otherwise function app will face error when start.)并且您需要安装 python 3.8.x(请注意您必须下载 64 位。否则 function 应用程序将在启动时遇到错误。)

2, Configure the Python to the system path. 2、配置Python到系统路径。

3, install function extension and Python debug extension in VS code. 3、在VS代码中安装function扩展和Python调试扩展。

4, press f1 and input 'func', you will find the create function options. 4、按f1并输入'func',你会发现创建function选项。

5, Follow the steps you will create the function. 5,按照您将创建 function 的步骤。 Then use below code:然后使用下面的代码:

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "event",
      "direction": "in"
    },
    {
      "name": "inputblob",
      "type": "blob",
      "path": "test1/6.txt",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "in"
    },
    {
      "name": "outputblob",
      "type": "blob",
      "path": "test2/6.txt",
      "connection": "MyStorageConnectionAppSetting",
      "direction": "out"
    }
  ]
}

local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "MyStorageConnectionAppSetting":"DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxxxxx==;EndpointSuffix=core.windows.net"
  }
}

__init__py

import json
import logging

import azure.functions as func


def main(event: func.EventGridEvent, inputblob: func.InputStream, outputblob: func.Out[func.InputStream]):
    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)

    #Do something here. you can change below inputblob to other stream.

    outputblob.set(inputblob)

After all of the above steps, create a event grid subscription and deploy your function app to azure.完成上述所有步骤后,创建事件网格订阅并将 function 应用程序部署到 azure。 Point the event grid to your function app.将事件网格指向您的 function 应用程序。 Then When A event comes, the function will be triggered.那么当A事件来临时,function就会被触发。

The thing you need notice is Binder not supported in Python, so...the path can not be specified in running.(This is a pity. Ibinder only supported for.Net based language.)需要注意的是 Python 中不支持 Binder,所以......运行时无法指定路径。(很遗憾。Ibinder 仅支持基于 .Net 的语言。)

Above is your requirement, It can works but the blob path cannot be dynamic... I think for your situation, the more suitable way is to use blobtrigger and blob output binding.(This can get the blob name from trigger to output.)以上是你的要求,它可以工作,但blob路径不能是动态的......我认为对于你的情况,更合适的方法是使用blobtrigger和blob output绑定。(这可以从触发器获取blob名称到output。)

暂无
暂无

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

相关问题 如何使用 Azure 函数从 Blob 存储中读取 json 文件 Python - How to read json file from blob storage using Azure Functions Blob Trigger with Python Azure 功能 - Python(Blob 触发器和绑定) - Azure Functions - Python (Blob Trigger and Binding) 如何在 Python 中使用 Azure Functions 的 Azure Blob 存储绑定将 JSON 数据上传到 Azure 存储 blob - How to upload JSON data to Azure storage blob using Azure Blob storage bindings for Azure Functions in Python 使用 python azure 函数从 azure blob 存储读取文件 - Read files from azure blob storage using python azure functions 时间触发的 Python 中的 Azure 函数从 url 获取 zip 文件,解压缩,然后将文件输出到 Azure 存储中的 blob 容器 - Azure Function in Python that is on a time trigger get zip file from a url, unzip, then output file to blob container in Azure storage Azure blob 存储函数可以与多个输入绑定吗? - Can Azure blob storage functions bind with multiple input? 使用python azure函数检查文件是否存在于blob存储中 - Check if file exists in blob storage using python azure functions 使用 Azure 函数中的 Python 根据 Azure Blob 存储中的模式匹配检查 Blob 是否存在 - Check Existence of Blob based on Pattern match in Azure Blob Storage using Python in Azure Functions 将输出写入 Azure Functions 中的 Blob - Write output to Blob in Azure Functions 如何为 python 的 azure 函数中的 Blob 动态设置 output 名称 - How to dynamically set the output name for a blob in azure functions for python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM