如何在带有事件中心的 ARM 模板中使用 listkeys 函数

How to use listkeys function in an ARM Template with Event Hub

我有一个如下所示的事件中心:

我已经为服务总线成功完成了,但仅适用于高级 RootManageSharedAccessKey.

但是对于事件中心,我想要 SendOnly 共享访问策略的主连接字符串。

我尝试了很多组合,但是我在部署时找不到 SendOnly 共享访问策略。

这是我的 SendOnly 共享访问策略的json。

任何帮助将不胜感激。

使用它来获取连接字符串:

"[listkeys(resourceId('Microsoft.Eventhub/namespaces/authorizationRules',
  parameters('name'), 'RootManageSharedAccessKey'),
  '2017-04-01').primaryConnectionString]"

你不能跨行拆分它,我这样做是为了便于阅读

最终工作的 ARM 模板代码是:

[listkeys(resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', variables('ehub').name, parameters('eventhubs_myaccountevents_name'), 'SendOnly'), parameters('eventhubs_api_version')).primaryConnectionString]

请注意,而不是这个:

Microsoft.Eventhub/namespaces/authorizationRules

我不得不使用这个:

Microsoft.EventHub/namespaces/eventhubs/authorizationRules

这是我使用的示例: https://github.com/pascalnaber/EnterpriseARMTemplates/blob/6babc4d3e65f10f999bb144a1d616ccb2a085e9d/templates/resources/Microsoft.Eventhub/azuredeploy.json

我是这样解决的(包括创建授权规则):

定义变量:

...
"variables": {
    "eventHubNamespaceName": "myehubns",
    "eventHubName": "myehub",
    "eventhubSendAuthorizationRuleName": "SendOnly",
    "eventHubSendRuleId": "[resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', variables('eventHubNamespaceName'),variables('eventHubName'), variables('eventhubSendAuthorizationRuleName'))]"
}

创建授权规则:

...
"resources": [{
        "apiVersion": "2017-04-01",
        "name": "[variables('eventhubSendAuthorizationRuleName')]",
        "type": "authorizationRules",
        "dependsOn": [
            "[concat('Microsoft.EventHub/namespaces/', variables('eventHubNamespaceName'),'/eventhubs/',variables('eventHubName'))]"
        ],
        "properties": {
            "rights": [
                "Send"
            ]
        }
    }
]

检索先前创建的规则的主连接字符串:

"EventHubConnectionstring": "[listkeys(variables('eventHubSendRuleId'), '2017-04-01').primaryConnectionString]"