首页 > 解决方案 > 为 Azure 函数创建 EvenGridSubscription 时尝试验证提供的端点失败

问题描述

我正在尝试为使用EventGridTrigger的 Azure 函数创建 EventGridSubscription。运行New-AzureRmEventGridSubscription cmdlet 时,我看到以下错误:

网址验证:尝试验证提供的端点https://blablafunction.azurewebsites.net/admin/EventGridExtensionConfig失败。

这是天蓝色的功能代码:

[FunctionName("BlobCreatedHandler")]
public static async Task Run([EventGridTrigger]JObject blobEvent,
    [Queue("blob-created-queue", Connection = Strings.StorageAccountConnection)] CloudQueue blobCreatedQueue,
    [Inject(typeof(IBlobCreatedHandler))] IBlobCreatedHandler blobCreatedHandler)
{
    await blobCreatedHandler.Handle(blobEvent, blobCreatedQueue);
}

我尝试了不同版本的 AzureRM.EventGrid 模块。有趣的是,在低于 0.3.0 的版本上它可以正常工作。但是从 0.3.1 开始的所有最新版本都因此错误而失败。有人有同样的经历吗?

UPD: Fiddler 说两个版本的 SDK(好的版本和坏版本)都发送完全相同的请求:

{
"properties": {
    "destination": {
        "endpointType": "WebHook",
        "properties": {
            "endpointUrl": "https://blobmalwarescanapptest.azurewebsites.net/admin/EventGridExtensionConfig?functionName=TestFunc&code=PhWghMXtSma188UQccaoErA4Eiw7ygudguHkpq1V0XKMfzA59yBR5g=="
        }
    },
    "filter": {
        "includedEventTypes": [
            "All"
        ],
        "isSubjectCaseSensitive": false
    }
}

并得到完全相同的回应。但是在较新版本的 SDK 上,Azure EventGrid 管理端点似乎会截断“?”之后的所有内容。签名并尝试验证基本 url(没有查询参数)。

标签: azure-eventgrid

解决方案


我刚刚使用 ARM 模板来实现相同的结果。对我有用的端点是: https://<FunctionAppName>.azurewebsites.net/runtime/webhooks/EventGrid?functionName=<functionName>&code=<code>

虽然这也适用于 azure 函数的 v2,但我看到您正在使用 v1(因为 JObject 作为 eventgrid 触发器)。

编辑:我的 ARM 模板示例:

{
  "type": "Microsoft.Storage/storageAccounts/providers/eventSubscriptions",
  "name": "[concat(variables('MobileStorageName'), '/Microsoft.EventGrid/', variables('EventSubscriberName'))]",
  "apiVersion": "2018-01-01",
  "dependsOn": [
    "[variables('MobileStorageName')]"
  ],
  "tags": {
    "displayName": "Storage Account Event Subscription"
  },
  "properties": {
    "destination": {
      "endpointType": "WebHook",
      "properties": {
        "endpointUrl": "[variables('FunctionAppEndpoint')]"
      }
    },
    "filter": {
      "subjectBeginsWith": "",
      "subjectEndsWith": "",
      "isSubjectCaseSensitive": false,
      "includedEventTypes": [ "Microsoft.Storage.BlobCreated" ]
    }
  }
}

请注意,在我的情况下,我需要 StorageV2(它是 2018-02-1 api),否则它不起作用。


推荐阅读