使用 ARM 模板的 Azure IoT 事件订阅
Azure IoT event subscription with ARM template
我正在尝试使用 ARM 模板和 PowerShell 将 Azure IoT 设备连接的事件订阅部署到 Azure 存储队列。我使用了以下模板来部署它。另外,我已经阅读了很多关于微软的文章。但找不到任何解决方案。请帮我弄清楚。
"resources": [
{
"type": "Microsoft.EventGrid/eventSubscriptions",
"name": "DeviceConnected",
"location": "[resourceGroup().location]",
"apiVersion": "2018-01-01",
"dependsOn": [
"[resourceId('Microsoft.Devices/IotHubs', variables('iotHubName'))]"
],
"properties": {
"destination": {
"endpointType": "storagequeue",
"properties": {
"queueName":"device-connnection-state-queue",
"resourceId": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageName'))]"
}
},
"filter": {
"includedEventTypes": [
"Microsoft.Devices.DeviceConnected"
]
}
}
}
],
错误显示如下
您看到的错误与您指定的 dependsOn
属性 有关。
Resources that must be deployed before this resource is deployed. Resource Manager evaluates the dependencies between resources and deploys them in the correct order. When resources aren't dependent on each other, they're deployed in parallel. The value can be a comma-separated list of a resource names or resource unique identifiers. Only list resources that are deployed in this template. Resources that aren't defined in this template must already exist. Avoid adding unnecessary dependencies as they can slow your deployment and create circular dependencies. For guidance on setting dependencies, see Defining dependencies in Azure Resource Manager templates.
所以没有在ARM模板中定义的资源不能在DependsOn
属性中使用。
这里是事件订阅创建相关的文档:
Microsoft.EventGrid eventSubscriptions template reference
关于如何创建事件订阅的示例不多,但您可以从 Azure 门户中提取部分模板:
点击+ Event Subscription
填写详细信息
点击右上角的Advanced Editor button
link
它将向您展示创建 ARM 模板所需的一些详细信息
示例 ARM 模板如下所示:
"resources": [
{
"type": "Microsoft.Devices/IotHubs/providers/eventSubscriptions",
"apiVersion": "2019-01-01",
"name": "[concat(parameters('iotHubName'), '/Microsoft.EventGrid/', parameters('eventSubName'))]",
"location": "[resourceGroup().location]",
"properties": {
"topic": "[resourceId('Microsoft.Devices/IotHubs', parameters('iotHubName'))]",
"destination": {
"endpointType": "StorageQueue",
"properties": {
"resourceId": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]",
"queueName": "[parameters('queueName')]"
}
},
"filter": {
"includedEventTypes": [
"Microsoft.Devices.DeviceConnected"
],
"advancedFilters": []
},
"labels": [],
"eventDeliverySchema": "EventGridSchema"
}
}
]
我正在尝试使用 ARM 模板和 PowerShell 将 Azure IoT 设备连接的事件订阅部署到 Azure 存储队列。我使用了以下模板来部署它。另外,我已经阅读了很多关于微软的文章。但找不到任何解决方案。请帮我弄清楚。
"resources": [
{
"type": "Microsoft.EventGrid/eventSubscriptions",
"name": "DeviceConnected",
"location": "[resourceGroup().location]",
"apiVersion": "2018-01-01",
"dependsOn": [
"[resourceId('Microsoft.Devices/IotHubs', variables('iotHubName'))]"
],
"properties": {
"destination": {
"endpointType": "storagequeue",
"properties": {
"queueName":"device-connnection-state-queue",
"resourceId": "[resourceId('Microsoft.Storage/storageAccounts', variables('storageName'))]"
}
},
"filter": {
"includedEventTypes": [
"Microsoft.Devices.DeviceConnected"
]
}
}
}
],
错误显示如下
您看到的错误与您指定的
dependsOn
属性 有关。Resources that must be deployed before this resource is deployed. Resource Manager evaluates the dependencies between resources and deploys them in the correct order. When resources aren't dependent on each other, they're deployed in parallel. The value can be a comma-separated list of a resource names or resource unique identifiers. Only list resources that are deployed in this template. Resources that aren't defined in this template must already exist. Avoid adding unnecessary dependencies as they can slow your deployment and create circular dependencies. For guidance on setting dependencies, see Defining dependencies in Azure Resource Manager templates.
所以没有在ARM模板中定义的资源不能在
DependsOn
属性中使用。这里是事件订阅创建相关的文档:
Microsoft.EventGrid eventSubscriptions template reference
关于如何创建事件订阅的示例不多,但您可以从 Azure 门户中提取部分模板:
点击
+ Event Subscription
填写详细信息
点击右上角的
Advanced Editor button
link它将向您展示创建 ARM 模板所需的一些详细信息
示例 ARM 模板如下所示:
"resources": [
{
"type": "Microsoft.Devices/IotHubs/providers/eventSubscriptions",
"apiVersion": "2019-01-01",
"name": "[concat(parameters('iotHubName'), '/Microsoft.EventGrid/', parameters('eventSubName'))]",
"location": "[resourceGroup().location]",
"properties": {
"topic": "[resourceId('Microsoft.Devices/IotHubs', parameters('iotHubName'))]",
"destination": {
"endpointType": "StorageQueue",
"properties": {
"resourceId": "[resourceId('Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]",
"queueName": "[parameters('queueName')]"
}
},
"filter": {
"includedEventTypes": [
"Microsoft.Devices.DeviceConnected"
],
"advancedFilters": []
},
"labels": [],
"eventDeliverySchema": "EventGridSchema"
}
}
]