通过 ARM 模板对 EndpointType 为 AzureFunction 的主题进行事件订阅

Tec*_*uru 5 azure azure-resource-manager azure-rm-template azure-functions azure-eventgrid

我正在尝试使用"endpointType": "AzureFunction"创建事件网格主题订阅。它给出以下错误:-

"error": { "code": "InvalidRequest", "message": "无效的事件订阅请求:提供的 URL 无效。它不能为 null 或为空,并且应该是正确的 HTTPS URL,例如https://www.example。 com。” }

我的 ARM 模板如下:-

{
      "name": "[concat(variables('eventGridTopicName'), '/Microsoft.EventGrid/', variables('myFuncName'))]",
      "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
      "apiVersion": "2019-01-01",
      "location": "[parameters('location')]",
      "properties": {
        "topic": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('resourceGroupName'), '/providers/Microsoft.EventGrid/topics/', variables('eventGridTopicName'))]",
        "destination": {
          "endpointType": "AzureFunction",
          "properties": {
            "resourceId": "[resourceId('Microsoft.Web/sites/functions/', variables('funcAppName'), variables('myFuncName'))]",
            "maxEventsPerBatch": 1,
            "preferredBatchSizeInKilobytes": 64
          }
        },
        "filter": {
          "advancedFilters": [
            {
              "operatorType": "StringIn",
              "key": "eventType",
              "values": [
                "xyzEvent"
              ]
            },
            {
              "operatorType": "StringIn",
              "key": "subject",
              "values": [
                "xyzEventReceived"
              ]
            }
          ]
        },
        "labels": [],
        "eventDeliverySchema": "EventGridSchema"
      },
      "dependsOn": [
        "[variables('eventGridTopicName')]"
      ]
    }
Run Code Online (Sandbox Code Playgroud)

早些时候,我使用 EndpointType 作为 Webhook,因为新的事件处理程序(例如 Azure Function、存储队列等)不可用(https://learn.microsoft.com/en-us/azure/event-grid/event-handlers) 。我使用了从 Azure 门户生成的 Arm 模板,如下所示:-

在此输入图像描述

有人遇到过这个问题吗?

Tec*_*uru 2

Jakob 关于更改 api 版本的建议对我来说有效,并且更改了 resourceId。这是我修改后的工作模板:-

{
      "name": "[concat(variables('eventGridTopicName'), '/Microsoft.EventGrid/', variables('myFuncName'))]",
      "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
      "apiVersion": "2020-01-01-preview",
      "location": "[parameters('location')]",
      "properties": {
        "topic": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('resourceGroupName'), '/providers/Microsoft.EventGrid/topics/', variables('eventGridTopicName'))]",
        "destination": {
          "endpointType": "AzureFunction",
          "properties": {
            "resourceId": "[concat('/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('resourceGroupName'), '/providers/Microsoft.Web/sites/', variables('funcAppName'), '/functions/' , variables('myFuncName'))]",
            "maxEventsPerBatch": 1,
            "preferredBatchSizeInKilobytes": 64
          }
        },
        "filter": {
          "advancedFilters": [
            {
              "operatorType": "StringIn",
              "key": "eventType",
              "values": [
                "xyzEvent"
              ]
            },
            {
              "operatorType": "StringIn",
              "key": "subject",
              "values": [
                "xyzEventReceived"
              ]
            }
          ]
        },
        "labels": [],
        "eventDeliverySchema": "EventGridSchema"
      },
      "dependsOn": [
        "[variables('eventGridTopicName')]"
      ]
    }
Run Code Online (Sandbox Code Playgroud)