部署为 Azure 资源管理器 (ARM) 模板的流分析作业
Stream Analytics Job deployed as Azure Resource Manager (ARM) template
我正在尝试为定义为 JSON 模板的流分析作业设置 output EventHub。没有输出位,模板已成功部署,但是在添加输出定义时失败:
Deployment failed. Correlation ID: <SOME_UUID>. {
"code": "BadRequest",
"message": "The JSON provided in the request body is invalid. Property 'eventHubName' value 'parameters('eh_name')' is not acceptable.",
"details": {
"code": "400",
"message": "The JSON provided in the request body is invalid. Property 'eventHubName' value 'parameters('eh_name')' is not acceptable.",
"correlationId": "<SOME_UUID>",
"requestId": "<SOME_UUID>"
}
}
我将 ARM 模板定义为:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "westeurope"
},
"hubName": {
"type": "string",
"defaultValue": "fooIotHub"
},
"eh_name": {
"defaultValue": "fooEhName",
"type": "String"
},
"eh_namespace": {
"defaultValue": "fooEhNamespace",
"type": "String"
},
"streamAnalyticsJobName": {
"type": "string",
"defaultValue": "fooStreamAnalyticsJobName"
}
},
"resources": [{
"type": "Microsoft.StreamAnalytics/StreamingJobs",
"apiVersion": "2016-03-01",
"name": "[parameters('streamAnalyticsJobName')]",
"location": "[resourceGroup().location]",
"properties": {
"sku": {
"name": "standard"
},
"outputErrorPolicy": "Drop",
"eventsOutOfOrderPolicy": "adjust",
"eventsOutOfOrderMaxDelayInSeconds": 0,
"eventsLateArrivalMaxDelayInSeconds": 86400,
"inputs": [{
"Name": "IoTHubInputLable",
"Properties": {
"DataSource": {
"Properties": {
"iotHubNamespace": "[parameters('hubName')]",
"sharedAccessPolicyKey": "[listkeys(resourceId('Microsoft.Devices/IotHubs/IotHubKeys',parameters('hubName'), 'iothubowner'),'2016-02-03').primaryKey]",
"sharedAccessPolicyName": "iothubowner",
"endpoint": "messages/events"
},
"Type": "Microsoft.Devices/IotHubs"
},
"Serialization": {
"Properties": {
"Encoding": "UTF8"
},
"Type": "Json"
},
"Type": "Stream"
}
}],
"transformation": {
"name": "Transformation",
"properties": {
"streamingUnits": 1,
"query": "<THE SQL-LIKE CODE FOR THE JOB QUERY>"
}
},
"outputs": [{
"name": "EventHubOutputLable",
"properties": {
"dataSource": {
"type": "Microsoft.ServiceBus/EventHub",
"properties": {
"eventHubName": "parameters('eh_name')",
"serviceBusNamespace": "parameters('eh_namespace')",
"sharedAccessPolicyName": "RootManageSharedAccessKey"
}
},
"serialization": {
"Properties": {
"Encoding": "UTF8"
}
}
}
}]
}
}]
}
在此处查看https://docs.microsoft.com/en-us/azure/templates/microsoft.streamanalytics/streamingjobs
看起来 输出 的 JSON 的结构与预期的一样(properties
字段和 type
)。
我已经使用开发人员工具从 Chrome 浏览器中找到了那些 "Event Hub properties" 并检查了 HTTP 请求的详细信息 "GetOutputs",否则我不确定在哪里可以看到如何指定这些属性?该结构看起来与输入 IoT 中心(正在运行)的结构非常相似,在这种情况下,对与 IoT 中心详细信息相关的属性使用不同的标签。
查看此博客 post https://blogs.msdn.microsoft.com/david/2017/07/20/building-azure-stream-analytics-resources-via-arm-templates-part-2-the-template/
输出部分与 PowerBI 相关,看起来属性使用了不同的结构:outputPowerBISource
,因此我尝试将字段 outputEventHubSource
用于事件中心(来自使用 Chrome Developer Tools) 而不是 properties
,但我得到这个错误:
Deployment failed. Correlation ID: <SOME_UUID>. {
"code": "BadRequest",
"message": "The JSON provided in the request body is invalid. Required property 'properties' not found in JSON. Path '', line 1, position 1419.",
"details": {
"code": "400",
"message": "The JSON provided in the request body is invalid. Required property 'properties' not found in JSON. Path '', line 1, position 1419.",
"correlationId": "<SOME_UUID>",
"requestId": "<SOME_UUID>"
}
}
我用来部署此模板的命令是 Azure CLI(来自 Linux Debian 机器):
az group deployment create \
--name "deployStreamAnalyticsJobs" \
--resource-group "MyRGName" \
--template-file ./templates/stream-analytics-jobs.json
如何在 Azure 资源管理器 (ARM) 模板中为流分析作业指定 输出?
任何包含参数的属性(或任何需要计算的表达式必须包含方括号,例如
"eventHubName": "[parameters('eh_name')]",
"serviceBusNamespace": "[parameters('eh_namespace')]",
否则使用引号中的文字值。
有帮助吗?
我发现所有参数都需要用方括号括起来(正如这个问题的另一个答案所指出的)。
此外,要动态检索共享访问策略密钥(或现有资源(如事件中心)的任何其他参数),必须使用 listKeys
和 resourceId
等函数的组合,请参阅下面是描述为流分析作业输出的事件中心的完整示例。
详情:
- 为
eventHubName
和 serviceBusNamespace
定义的参数必须使用方括号进行评估(请参阅我在上面问的问题正文中的 JSON 示例中如何定义这些参数),
- 共享访问策略可以是像
sharedAccessPolicyName
这样的硬编码字符串(或以前的参数),也可以使用 "sharedAccessPolicyKey": "[listKeys(resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', parameters('eh_namespace'), parameters('eh_name'), 'RootManageSharedAccessKey'),'2017-04-01').primaryKey]"
为 sharedAccessPolicyKey
动态检索(这是敏感数据和它应该受到保护,避免将信息硬编码为纯字符串)
以下 JSON 配置显示定义为流分析作业定义的输出的现有事件中心:
"outputs": [{
"Name": "EventHubOutputLable",
"Properties": {
"DataSource": {
"Type": "Microsoft.ServiceBus/EventHub",
"Properties": {
"eventHubName": "[parameters('eh_name')]",
"serviceBusNamespace": "[parameters('eh_namespace')]",
"sharedAccessPolicyKey": "[listKeys(resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', parameters('eh_namespace'), parameters('eh_name'), 'RootManageSharedAccessKey'),'2017-04-01').primaryKey]",
"sharedAccessPolicyName": "RootManageSharedAccessKey"
}
},
"Serialization": {
"Properties": {
"Encoding": "UTF8"
},
"Type": "Json"
}
}
}]
我正在尝试为定义为 JSON 模板的流分析作业设置 output EventHub。没有输出位,模板已成功部署,但是在添加输出定义时失败:
Deployment failed. Correlation ID: <SOME_UUID>. {
"code": "BadRequest",
"message": "The JSON provided in the request body is invalid. Property 'eventHubName' value 'parameters('eh_name')' is not acceptable.",
"details": {
"code": "400",
"message": "The JSON provided in the request body is invalid. Property 'eventHubName' value 'parameters('eh_name')' is not acceptable.",
"correlationId": "<SOME_UUID>",
"requestId": "<SOME_UUID>"
}
}
我将 ARM 模板定义为:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "westeurope"
},
"hubName": {
"type": "string",
"defaultValue": "fooIotHub"
},
"eh_name": {
"defaultValue": "fooEhName",
"type": "String"
},
"eh_namespace": {
"defaultValue": "fooEhNamespace",
"type": "String"
},
"streamAnalyticsJobName": {
"type": "string",
"defaultValue": "fooStreamAnalyticsJobName"
}
},
"resources": [{
"type": "Microsoft.StreamAnalytics/StreamingJobs",
"apiVersion": "2016-03-01",
"name": "[parameters('streamAnalyticsJobName')]",
"location": "[resourceGroup().location]",
"properties": {
"sku": {
"name": "standard"
},
"outputErrorPolicy": "Drop",
"eventsOutOfOrderPolicy": "adjust",
"eventsOutOfOrderMaxDelayInSeconds": 0,
"eventsLateArrivalMaxDelayInSeconds": 86400,
"inputs": [{
"Name": "IoTHubInputLable",
"Properties": {
"DataSource": {
"Properties": {
"iotHubNamespace": "[parameters('hubName')]",
"sharedAccessPolicyKey": "[listkeys(resourceId('Microsoft.Devices/IotHubs/IotHubKeys',parameters('hubName'), 'iothubowner'),'2016-02-03').primaryKey]",
"sharedAccessPolicyName": "iothubowner",
"endpoint": "messages/events"
},
"Type": "Microsoft.Devices/IotHubs"
},
"Serialization": {
"Properties": {
"Encoding": "UTF8"
},
"Type": "Json"
},
"Type": "Stream"
}
}],
"transformation": {
"name": "Transformation",
"properties": {
"streamingUnits": 1,
"query": "<THE SQL-LIKE CODE FOR THE JOB QUERY>"
}
},
"outputs": [{
"name": "EventHubOutputLable",
"properties": {
"dataSource": {
"type": "Microsoft.ServiceBus/EventHub",
"properties": {
"eventHubName": "parameters('eh_name')",
"serviceBusNamespace": "parameters('eh_namespace')",
"sharedAccessPolicyName": "RootManageSharedAccessKey"
}
},
"serialization": {
"Properties": {
"Encoding": "UTF8"
}
}
}
}]
}
}]
}
在此处查看https://docs.microsoft.com/en-us/azure/templates/microsoft.streamanalytics/streamingjobs
看起来 输出 的 JSON 的结构与预期的一样(properties
字段和 type
)。
我已经使用开发人员工具从 Chrome 浏览器中找到了那些 "Event Hub properties" 并检查了 HTTP 请求的详细信息 "GetOutputs",否则我不确定在哪里可以看到如何指定这些属性?该结构看起来与输入 IoT 中心(正在运行)的结构非常相似,在这种情况下,对与 IoT 中心详细信息相关的属性使用不同的标签。
查看此博客 post https://blogs.msdn.microsoft.com/david/2017/07/20/building-azure-stream-analytics-resources-via-arm-templates-part-2-the-template/
输出部分与 PowerBI 相关,看起来属性使用了不同的结构:outputPowerBISource
,因此我尝试将字段 outputEventHubSource
用于事件中心(来自使用 Chrome Developer Tools) 而不是 properties
,但我得到这个错误:
Deployment failed. Correlation ID: <SOME_UUID>. {
"code": "BadRequest",
"message": "The JSON provided in the request body is invalid. Required property 'properties' not found in JSON. Path '', line 1, position 1419.",
"details": {
"code": "400",
"message": "The JSON provided in the request body is invalid. Required property 'properties' not found in JSON. Path '', line 1, position 1419.",
"correlationId": "<SOME_UUID>",
"requestId": "<SOME_UUID>"
}
}
我用来部署此模板的命令是 Azure CLI(来自 Linux Debian 机器):
az group deployment create \
--name "deployStreamAnalyticsJobs" \
--resource-group "MyRGName" \
--template-file ./templates/stream-analytics-jobs.json
如何在 Azure 资源管理器 (ARM) 模板中为流分析作业指定 输出?
任何包含参数的属性(或任何需要计算的表达式必须包含方括号,例如
"eventHubName": "[parameters('eh_name')]",
"serviceBusNamespace": "[parameters('eh_namespace')]",
否则使用引号中的文字值。
有帮助吗?
我发现所有参数都需要用方括号括起来(正如这个问题的另一个答案所指出的)。
此外,要动态检索共享访问策略密钥(或现有资源(如事件中心)的任何其他参数),必须使用 listKeys
和 resourceId
等函数的组合,请参阅下面是描述为流分析作业输出的事件中心的完整示例。
详情:
- 为
eventHubName
和serviceBusNamespace
定义的参数必须使用方括号进行评估(请参阅我在上面问的问题正文中的 JSON 示例中如何定义这些参数), - 共享访问策略可以是像
sharedAccessPolicyName
这样的硬编码字符串(或以前的参数),也可以使用"sharedAccessPolicyKey": "[listKeys(resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', parameters('eh_namespace'), parameters('eh_name'), 'RootManageSharedAccessKey'),'2017-04-01').primaryKey]"
为sharedAccessPolicyKey
动态检索(这是敏感数据和它应该受到保护,避免将信息硬编码为纯字符串)
以下 JSON 配置显示定义为流分析作业定义的输出的现有事件中心:
"outputs": [{
"Name": "EventHubOutputLable",
"Properties": {
"DataSource": {
"Type": "Microsoft.ServiceBus/EventHub",
"Properties": {
"eventHubName": "[parameters('eh_name')]",
"serviceBusNamespace": "[parameters('eh_namespace')]",
"sharedAccessPolicyKey": "[listKeys(resourceId('Microsoft.EventHub/namespaces/eventhubs/authorizationRules', parameters('eh_namespace'), parameters('eh_name'), 'RootManageSharedAccessKey'),'2017-04-01').primaryKey]",
"sharedAccessPolicyName": "RootManageSharedAccessKey"
}
},
"Serialization": {
"Properties": {
"Encoding": "UTF8"
},
"Type": "Json"
}
}
}]