【问题标题】:How to make Azure Function triggered by Azure Event Grid with a binding to Blob Storage [duplicate]如何通过绑定到 Blob 存储的 Azure 事件网格触发 Azure 函数 [重复]
【发布时间】:2018-05-15 11:16:31
【问题描述】:

尝试使用 Visual Studio 在 c# 中重新制作 Azure Grid Image Resize 示例,但在使事件网格触发 azure 函数触发器并绑定到 blob 存储时遇到问题。

当前代码:

using Microsoft.Azure.WebJobs.Extensions.EventGrid;
using Microsoft.Azure.WebJobs.Host;
using Microsoft.Azure.WebJobs;
using Microsoft.WindowsAzure.Storage.Blob;

namespace FunctionApp
{
    public static class CreateIndex
    {
        [FunctionName("CreateIndex")]
        [StorageAccount("backup_STORAGE")]
        public static void Run(
            [EventGridTrigger()] EventGridEvent myEvent, 
            [Blob("{data.url}")] CloudBlockBlob inputBlob, 
            TraceWriter log)
        {
            log.Info(myEvent.ToString());
            log.Info(inputBlob.ToString());
        }
    }
}

生成的function.json:

{
  "generatedBy": "Microsoft.NET.Sdk.Functions.Generator-1.0.6",
  "configurationSource": "attributes",
  "bindings": [
    {
      "type": "eventGridTrigger",
      "name": "myEvent"
    }
  ],
  "disabled": false,
  "scriptFile": "../bin/FunctionApp.dll",
  "entryPoint": "FunctionApp.CreateIndex.Run"
}

绑定适用于事件网格触发器,但不适用于 Blob 输入。

预期函数.json:

{
  "bindings": [
    {
      "type": "EventGridTrigger",
      "name": "myEvent",
      "direction": "in"
    },
    {
      "type": "blob",
      "name": "inputBlob",
      "path": "{data.url}",
      "connection": "myblobstorage_STORAGE",
      "direction": "in"
    }
  ],
  "disabled": false
}

【问题讨论】:

    标签: azure azure-functions azure-eventgrid


    【解决方案1】:

    预编译的函数会为您生成function.json,但它们只将触发器绑定放在其中。您的 blob 绑定不在此文件中,这没关系。

    输入 Blob 绑定仍然有效:运行时将根据您的属性选择它。

    【讨论】:

      猜你喜欢
      • 2021-10-08
      • 2021-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-29
      • 2018-04-19
      • 2021-11-05
      • 2018-03-17
      相关资源
      最近更新 更多