快速入门:使用 ARM 模板创建 Azure 流分析作业Quickstart: Create an Azure Stream Analytics job by using an ARM template

本快速入门将使用 Azure 资源管理器模板(ARM 模板)创建 Azure 流分析作业。In this quickstart, you use an Azure Resource Manager template (ARM template) to create an Azure Stream Analytics job. 创建作业后,将验证部署。Once the job is created, you validate the deployment.

ARM 模板是定义项目基础结构和配置的 JavaScript 对象表示法 (JSON) 文件。An ARM template is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. 该模板使用声明性语法,使你可以声明要部署的内容,而不需要编写一系列编程命令来进行创建。The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it.

如果你的环境满足先决条件,并且你熟悉如何使用 ARM 模板,请选择“部署到 Azure”按钮。If your environment meets the prerequisites and you're familiar with using ARM templates, select the Deploy to Azure button. Azure 门户中会打开模板。The template will open in the Azure portal.

部署到 AzureDeploy to Azure

先决条件Prerequisites

若要完成本文,需要做好以下准备:To complete this article, you need to:

查看模板Review the template

本快速入门中使用的模板来自 Azure 快速启动模板The template used in this quickstart is from Azure Quickstart Templates.

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.1.0.0",
  "parameters": {
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for the resources."
      }
    },
    "streamAnalyticsJobName": {
      "type": "string",
      "minLength": 3,
      "maxLength": 63,
      "metadata": {
        "description": "Stream Analytics Job Name, can contain alphanumeric characters and hypen and must be 3-63 characters long"
      }
    },
    "numberOfStreamingUnits": {
      "type": "int",
      "minValue": 1,
      "maxValue": 48,
      "allowedValues": [
        1,
        3,
        6,
        12,
        18,
        24,
        30,
        36,
        42,
        48
      ],
      "metadata": {
        "description": "Number of Streaming Units"
      }
    }
  },
  "resources": [
    {
      "type": "Microsoft.StreamAnalytics/StreamingJobs",
      "apiVersion": "2019-06-01",
      "name": "[parameters('streamAnalyticsJobName')]",
      "location": "[parameters('location')]",
      "properties": {
        "sku": {
          "name": "standard"
        },
        "outputErrorPolicy": "stop",
        "eventsOutOfOrderPolicy": "adjust",
        "eventsOutOfOrderMaxDelayInSeconds": 0,
        "eventsLateArrivalMaxDelayInSeconds": 5,
        "dataLocale": "en-US",
        "transformation": {
          "name": "Transformation",
          "properties": {
            "streamingUnits": "[parameters('numberOfStreamingUnits')]",
            "query": "SELECT\r\n    *\r\nINTO\r\n    [YourOutputAlias]\r\nFROM\r\n    [YourInputAlias]"
          }
        }
      }
    }
  ]
}

模板中定义的 Azure 资源是 Microsoft.StreamAnalytics/StreamingJobs:创建 Azure 流分析作业。The Azure resource defined in the template is Microsoft.StreamAnalytics/StreamingJobs: create an Azure Stream Analytics job.

部署模板Deploy the template

本部分介绍如何使用 ARM 模板创建 Azure 流分析作业。In this section, you create an Azure Stream Analytics job using the ARM template.

  1. 选择下图登录到 Azure 并打开一个模板。Select the following image to sign in to Azure and open a template. 该模板会创建 Azure 流分析作业。The template creates an Azure Stream Analytics job.

    部署到 AzureDeploy to Azure

  2. 提供所需的值以创建 Azure 流分析作业。Provide the required values to create your Azure Stream Analytics job.

    使用 Azure 资源管理器模板创建 Azure 流分析作业Create Azure Stream Analytics job using an Azure Resource Manager template

    提供以下值:Provide the following values:

    propertiesProperty 说明Description
    订阅Subscription 从下拉列表中选择自己的 Azure 订阅。From the drop-down, select your Azure subscription.
    资源组Resource group 指定是要创建新的资源组还是使用现有的资源组。Specify whether you want to create a new resource group or use an existing one. 资源组是用于保存 Azure 解决方案相关资源的容器。A resource group is a container that holds related resources for an Azure solution. 有关详细信息,请参阅 Azure 资源组概述For more information, see Azure Resource Group overview.
    区域Region 选择“中国北部”。Select China North. 有关其他可用区域,请参阅各区域推出的 Azure 服务For other available regions, see Azure services available by region.
    流分析作业名称Stream Analytics Job Name 提供流分析作业的名称。Provide a name for your Stream Analytics job.
    流单元数Number of Streaming Units 选择所需的流单元数。Choose the number of streaming units you need. 有关详细信息,请参阅了解和调整流单元For more information, see Understand and adjust Streaming Units.
  3. 选择“查看 + 创建”,然后选择“创建” 。Select Review + Create, then Create.

查看已部署的资源Review deployed resources

可以使用 Azure 门户检查 Azure 流分析作业,或者使用以下 Azure CLI 或 Azure PowerShell 脚本来列出资源。You can either use the Azure portal to check the Azure Stream Analytics job or use the following Azure CLI or Azure PowerShell script to list the resource.

Azure CLIAzure CLI

echo "Enter your Azure Stream Analytics job name:" &&
read streamAnalyticsJobName &&
echo "Enter the resource group where the Azure Stream Analytics job exists:" &&
read resourcegroupName &&
az stream-analytics job show -g $resourcegroupName -n $streamAnalyticsJobName

Azure PowerShellAzure PowerShell

$resourceGroupName = Read-Host -Prompt "Enter the resource group name where your Azure Stream Analytics job exists"
(Get-AzResource -ResourceType "Microsoft.StreamAnalytics/StreamingJobs" -ResourceGroupName $resourceGroupName).Name
 Write-Host "Press [ENTER] to continue..."

清理资源Clean up resources

如果打算继续学习后续教程,可能需要保留这些资源。If you plan to continue on to subsequent tutorials, you may wish to leave these resources in place. 如果不再需要资源组,可以将其删除,这会删除 Azure 流分析作业。When no longer needed, delete the resource group, which deletes the Azure Stream Analytics job. 使用 Azure CLI 或 Azure PowerShell 删除资源组:To delete the resource group by using Azure CLI or Azure PowerShell:

Azure CLIAzure CLI

echo "Enter the Resource Group name:" &&
read resourceGroupName &&
az group delete --name $resourceGroupName &&
echo "Press [ENTER] to continue ..."

Azure PowerShellAzure PowerShell

$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name"
Remove-AzResourceGroup -Name $resourceGroupName
Write-Host "Press [ENTER] to continue..."

后续步骤Next steps

在本快速入门中,你已使用 ARM 模板创建了 Azure 流分析作业,并验证了部署。In this quickstart, you created an Azure Stream Analytics job by using an ARM template and validated the deployment. 要了解如何使用 VS Code 导出现有作业的 ARM 模板,请继续阅读下一篇文章。Advance to the next article to learn how to export an ARM template for an existing job using VS Code.