azure - 通过 ARM 创建对自定义事件网格主题的存储队列订阅

标签 azure azure-rm-template azure-eventgrid

我正在尝试从自定义主题设置对我的存储队列的事件网格订阅。

在门户中导航时这很容易做到,但我无法为此创建适当的 ARM 模板。经过大量搜索和尝试后,我想出了以下模板。

{
    "name": "MyCustomTopicName/Microsoft.EventGrid/MySubscriptionName",
    "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
    "location": "[resourceGroup().location]",
    "apiVersion": "2019-06-01",
    "properties": {
        "destination": {
            "endpointType": "StorageQueue",
            "properties": {
                "resourceId": "[resourceId('Microsoft.Storage/storageAccounts', variables('theNameOfMyStorageAccount'))]",
                "queueName": "[variables('theNameOfMyQueue')]"
            }
        },
        "filter": {
            "advancedFilters": []
        },
        "labels": [],
        "eventDeliverySchema": "EventGridSchema"
    }
}

这对我来说看起来相当不错,但失败了,因为事件网格主题不在我要部署模板的资源组中。

Deployment failed. Correlation ID: [guid]. {
  "error": {
    "code": "ResourceNotFound",
    "message": "The Resource 'Microsoft.EventGrid/topics/MyCustomTopicName' under resource group 'TheResourceGroupTheStorageAccountIsIn' was not found."
  }
}

我正在将完整的 ARM 模板部署到 TheResourceGroupTheStorageAccountIsInMyCustomTopicName 主题位于我们放置自定义主题的资源组中,因此所有服务都可以使用它。

我尝试使用自定义主题的完整标识符(资源 ID),但这无效。有想法吗?

PS:我正在使用类似的模板来创建 Azure Functions 的订阅,该模板工作正常。主要区别在于 destination block ,这是有道理的。

最佳答案

如果我没看错的话,您只需要使用嵌套部署并定位主题所在的资源组:

{
    "apiVersion": "2017-05-10",
    "name": "nestedTemplate",
    "type": "Microsoft.Resources/deployments",
    "resourceGroup": "your_topic_resource_roup",
    "properties": {
        "mode": "Incremental",
        "template": {
            "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
            "contentVersion": "1.0.0.0",
            "parameters": {},
            "variables": {},
            "resources": [
                {
                    "name": "MyCustomTopicName/Microsoft.EventGrid/MySubscriptionName",
                    "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
                    "location": "[resourceGroup().location]",
                    "apiVersion": "2019-06-01",
                    "properties": {
                        "destination": {
                            "endpointType": "StorageQueue",
                            "properties": {
                                "resourceId": "[resourceId('Microsoft.Storage/storageAccounts', variables('theNameOfMyStorageAccount'))]",
                                "queueName": "[variables('theNameOfMyQueue')]"
                            }
                        },
                        "filter": {
                            "advancedFilters": []
                        },
                        "labels": [],
                        "eventDeliverySchema": "EventGridSchema"
                    }
                }
            ]
        }
    }
},

关于azure - 通过 ARM 创建对自定义事件网格主题的存储队列订阅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59213904/

相关文章:

azure - 是否可以将 AzureAppConfiguration 与 Azure Function ServiceBusTrigger 一起使用

c# - 事件网格客户端 : should it be disposed?

node.js - Nuxt 3 应用程序 GitHub Actions Build 中的 NewtonSoft.Json 异常

azure - Azure 计费 API 是否取决于部署模型?

azure - ARM 模板 key 保管库访问策略到组而不是身份原则

azure - PRODConfirmInvitationCode : "Could not fetch access token for Azure. Status code: 401, status message: Unauthorized"

azure - Microsoft.Azure.WebJobs.Extensions.EventGrid : Object reference not set to an instance of an object

c# - 库 : Microsoft. Azure.EventGrid 和 Azure.Messaging.EventGrid 之间的差异

powershell - 运行Azure虚拟机启动任务的正确方法是什么

json - 将一个arm部署资源链接模板的输出传递到另一个