簡體   English   中英

ARM 模板對 EndpointType 為 AzureFunction 的主題的事件訂閱

[英]Event subscription by ARM template for topic with EndpointType as AzureFunction

我正在嘗試使用"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')]"
      ]
    }

早些時候,我使用 EndpointType 作為 webhook,因為 Azure 函數、存儲隊列等新事件處理程序不可用 ( https://docs.microsoft.com/en-us/azure/event-grid/event-handlers ) . 我使用了從 Azure 門戶生成的 arm 模板,如下所示:-

在此處輸入圖片說明

有沒有人遇到過這個問題?

是的 ! 當我遇到同樣的問題時發現了這個! ..

更新! 找到了一個使用另一個 API 版本的示例,它似乎工作得更好,現在我的問題是第一次部署時沒有代碼,所以我需要將模板分成兩部分並在 btween 中部署內容(或通過模板 ofc)。

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM