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

时间:2020-02-13 12:11:22

标签: azure azure-functions azure-resource-manager arm-template azure-eventgrid

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

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

我的ARM模板如下:-

const date = new Date(`${date from client} GMT`);

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

enter image description here

有人遇到这个问题吗?

3 个答案:

答案 0 :(得分:2)

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

更新!找到了一个使用另一个API版本的示例,它似乎可以更好地工作,现在我的问题是第一次部署时上面没有代码,因此我需要将模板一分为二并在btween中部署内容(或通过的模板)。

“ apiVersion”:“ 2020-01-01-preview”,

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"
            }
        }

答案 1 :(得分:1)

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

答案 2 :(得分:0)

在我的场景中,我尝试使用“AzureFunctionEventSubscriptionDestination”作为目标将函数应用订阅添加到事件网格主题。我的问题是我没有将 /functions/{targetFunctionName} 添加到资源 ID。

"resourceId": "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{functionAppName}/functions/{targetFunctionName}"