快速入门:使用 ARM 模板创建认知服务资源Quickstart: Create a Cognitive Services resource using an ARM template

本快速入门介绍如何使用 Azure 资源管理器模板(ARM 模板)创建认知服务。This quickstart describes how to use an Azure Resource Manager template (ARM template) to create Cognitive Services.

Azure 认知服务是包含 REST API 和客户端库 SDK 的云服务,可帮助开发人员将认知智能内置于应用程序,而无需具备直接的人工智能 (AI) 或数据科学技能或知识。Azure Cognitive Services are cloud-base services with REST APIs, and client library SDKs available to help developers build cognitive intelligence into applications without having direct artificial intelligence (AI) or data science skills or knowledge. 借助 Azure 认知服务,开发人员可以通过能够看、听、说、理解甚至开始推理的认知解决方案,轻松将认知功能添加到他们的应用程序中。Azure Cognitive Services enables developers to easily add cognitive features into their applications with cognitive solutions that can see, hear, speak, understand, and even begin to reason.

使用 Azure 资源管理器模板(ARM 模板)创建资源。Create a resource using an Azure Resource Manager template (ARM template). 借助这个多服务资源可以实现以下操作:This multi-service resource lets you:

  • 通过单个密钥和终结点访问多个 Azure 认知服务。Access multiple Azure Cognitive Services with a single key and endpoint.
  • 合并所用资源的计费。Consolidate billing from the services you use.

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 your cognitive service to Azure

先决条件Prerequisites

查看模板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.0.0.0",
  "parameters": {
    "cognitiveServiceName": {
      "type": "string",
      "defaultValue": "[concat('CognitiveService-', uniqueString(resourceGroup().id))]",
      "metadata": {
        "description": "That name is the name of our application. It has to be unique.Type a name followed by your resource group name. (<name>-<resourceGroupName>)"
      }
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Location for all resources."
      }
    },
    "sku": {
      "type": "string",
      "defaultValue": "S0",
      "allowedValues": [
        "S0"
      ]
    }
  },
  "resources": [
    {
      "type": "Microsoft.CognitiveServices/accounts",
      "apiVersion": "2017-04-18",
      "name": "[parameters('cognitiveServiceName')]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('sku')]"
      },
      "kind": "CognitiveServices",
      "properties": {
        "statisticsEnabled": false
      }
    }
  ]
}

模板中定义了一个 Azure 资源:One Azure resource is defined in the template:

部署模板Deploy the template

  1. 单击“部署到 Azure”按钮。Click the Deploy to Azure button.

    部署到 AzureDeploy to Azure

  2. 输入以下值。Enter the following values.

    Value 说明Description
    订阅Subscription 选择 Azure 订阅。Select an Azure subscription.
    资源组Resource group 选择“新建”,输入资源组的唯一名称,然后单击“确定” 。Select Create new, enter a unique name for the resource group, and then click OK.
    区域Region 选择区域。Select a region. 例如,“中国东部 2”For example, China East 2
    认知服务名称Cognitive Service Name 替换为资源的唯一名称。Replace with a unique name for your resource. 在下一部分验证部署时,需要该名称。You will need the name in the next section when you validate the deployment.
    位置Location 替换为上面使用的区域。Replace with the region used above.
    SkuSku 资源的定价层The pricing tier for your resource.

    “创建资源”屏幕。

  3. 选择“查看 + 创建”,然后选择“创建” 。Select Review + Create, then Create. 资源部署成功完成后,“转到资源”按钮会高亮显示。After the resource has successfully finished deploying, the Go to resource button will be highlighted.

提示

如果订阅不允许创建认知服务资源,则可能需要使用 Azure 门户PowerShell 命令Azure CLI 命令启用 Azure 资源提供程序的功能。If your subscription doesn't allow you to create a Cognitive Service resource, you may need to enable that ability of the Azure resource provider with the Azure portal, PowerShell command or an Azure CLI command. 如果你不是订阅所有者,可请求订阅所有者或具有管理员角色的人员帮助你完成注册,或请求向你的帐户授予 /register/action 特权 。If you are not the subscription owner, ask the Subscription Owner or someone with a role of admin to complete the registration for you or ask for the /register/action privileges granted to your account.

查看已部署的资源Review deployed resources

部署完成后,单击“转到资源”按钮以查看新资源。When your deployment finishes, you will be able to click the Go to resource button to see your new resource. 通过以下方式也可找到该资源组:You can also find the resource group by:

  1. 在左侧导航菜单中选择“资源组”。Selecting Resource groups from the left navigation menu.
  2. 选择资源组名称。Selecting the resource group name.

清理资源Clean up resources

如果想要清理并删除认知服务订阅,可以删除资源或资源组。If you want to clean up and remove a Cognitive Services subscription, you can delete the resource or resource group. 删除资源组时也会删除资源组中包含的任何其他资源。Deleting the resource group also deletes any other resources contained in the group.

  1. 在 Azure 门户中展开左侧的菜单,打开服务菜单,然后选择“资源组”以显示资源组的列表。In the Azure portal, expand the menu on the left side to open the menu of services, and choose Resource Groups to display the list of your resource groups.
  2. 找到包含要删除的资源的资源组。Locate the resource group containing the resource to be deleted
  3. 右键单击资源组列表。Right-click on the resource group listing. 选择“删除资源组”并进行确认。Select Delete resource group, and confirm.

另请参阅See also