【问题标题】:Stream Analytics Job deployed as Azure Resource Manager (ARM) template流分析作业部署为 Azure 资源管理器 (ARM) 模板
【发布时间】:2018-08-14 13:35:50
【问题描述】:

我正在尝试为定义为 JSON 模板的流分析作业设置 输出 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 浏览器中找出了那些“事件中心属性”,并检查了 HTTP 请求“GetOutputs”的详细信息,否则我不确定在哪里可以看到如何指定这些属性?该结构看起来与输入 IoT 中心(正在工作)的结构非常相似,在这种情况下,对与 IoT 中心详细信息相关的属性使用不同的标签。

查看这篇博文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 开发人员工具的检查) 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) 模板中为流分析作业指定 输出

【问题讨论】:

    标签: azure azure-resource-manager azure-eventhub azure-stream-analytics azure-cli


    【解决方案1】:

    任何包含参数的属性(或任何需要计算的表达式都必须包含方括号,例如

    "eventHubName": "[parameters('eh_name')]",
    "serviceBusNamespace": "[parameters('eh_namespace')]",
    

    否则使用引号中的文字值。

    有帮助吗?

    【讨论】:

    • 是的,谢谢 :) 我很难找到这些细节......此外,为了检索一些动态细节,如共享访问策略,我必须使用答案中解释的功能组合我已经提供。
    【解决方案2】:

    我发现所有参数都需要用方括号括起来(正如该问题的另一个答案中所指出的那样)。

    此外,若要动态检索共享访问策略密钥(或现有资源(如事件中心)的任何其他参数),还必须使用 listKeysresourceId 等函数的组合,请参阅下面的完整示例描述为流分析作业的输出的事件中心。

    详细说明:

    • eventHubNameserviceBusNamespace 定义的参数必须使用方括号进行评估(请参阅我在上面提出的问题正文中的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"
                    }
                }
            }]
    

    【讨论】:

      猜你喜欢
      • 2020-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多