ARM 模板为 EndpointType 为 AzureFunction 的主题订阅事件

Event subscription by ARM template for topic with EndpointType as AzureFunction

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

"error": { "code": "InvalidRequest", "message": "Invalid event subscription request: Supplied URL is invalid. It cannot be null or empty and should be a proper HTTPS URL like 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')]"
      ]
    }

之前,我使用 EndpointType 作为 webhook,因为 Azure 函数、存储队列等新事件处理程序不可用 (https://docs.microsoft.com/en-us/azure/event-grid/event-handlers)。我使用了从 Azure 门户生成的 arm 模板,如下所示:-

有人遇到过这个问题吗?

是的!当我遇到同样的问题时发现了这个! ..

更新!找到了一个使用另一个 API 版本的例子,它似乎工作得更好,现在我的问题是第一次部署时没有代码,所以我需要将模板分成两部分并在中间部署内容(或通过模板 ofc 部署内容)。

"apiVersion": "2020-01-01-预览",

https://blog.brooksjc.com/2019/07/19/arm-template-for-event-grid-integration-with-a-new-azure-function/

更新2,添加内容后重新运行模板,一切正常!

这是我的存储触发器的完整代码

{
            "name": "[concat(variables('storageAccountName'), '/Microsoft.EventGrid/coreCostManagementExport')]",
            "type": "Microsoft.Storage/storageAccounts/providers/eventSubscriptions",
            "apiVersion": "2020-01-01-preview",
            "dependsOn": [
                "[resourceId('Microsoft.Storage/storageAccounts',variables('storageAccountName'))]",
                "[resourceId('Microsoft.Web/sites',parameters('functionAppName'))]"
            ],
            "properties": {
                "topic": "[resourceId('Microsoft.Storage/storageAccounts',variables('storageAccountName'))]",
                "destination": {
                    "endpointType": "AzureFunction",
                    "properties": {
                        "resourceId": "[resourceId('Microsoft.Web/sites/functions/', parameters('functionAppName'), 'QueueUsageOnExport')]",
                        "maxEventsPerBatch": 1,
                        "preferredBatchSizeInKilobytes": 64
                    }
                },
                "filter": {
                    "subjectBeginsWith": "/blobServices/default/containers/usage",
                    "subjectEndsWith": ".csv",
                    "includedEventTypes": [
                        "Microsoft.Storage.BlobCreated"
                    ],
                    "advancedFilters": [
                    ]
                },
                "labels": [
                ],
                "eventDeliverySchema": "EventGridSchema"
            }
        }

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')]"
      ]
    }

在我的方案中,我尝试使用“AzureFunctionEventSubscriptionDestination”作为目标向事件网格主题添加函数应用程序订阅。我的问题是我错过了将 /functions/{targetFunctionName} 添加到资源 ID。

“resourceId”:“/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft。Web/sites/{functionAppName}/functions/{targetFunctionName}”