你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

快速入门:使用 Bicep 文件创建 Batch 帐户

有关使用 Bicep 文件创建 Batch 帐户(包括存储)的 Azure Batch 快速入门。 需要一个 Batch 帐户来创建计算资源(计算节点池)和批处理作业。 可将 Azure 存储帐户与 Batch 帐户关联,后者可以用于为大多数现实世界的工作负荷部署应用程序和存储输入和输出数据。

完成本快速入门以后,你会了解 Batch 服务的重要概念,并可使用更逼真的工作负载进行更大规模的 Batch 试用。

Bicep 是一种特定于域的语言 (DSL),使用声明性语法来部署 Azure 资源。 它提供简明的语法、可靠的类型安全性以及对代码重用的支持。 Bicep 会针对你的 Azure 基础结构即代码解决方案提供最佳创作体验。

先决条件

必须拥有一个有效的 Azure 订阅。

查阅 Bicep 文件

本快速入门中使用的 Bicep 文件来自 Azure 快速入门模板

@description('Batch Account Name')
param batchAccountName string = '${toLower(uniqueString(resourceGroup().id))}batch'

@description('Storage Account type')
@allowed([
  'Standard_LRS'
  'Standard_GRS'
  'Standard_ZRS'
  'Premium_LRS'
])
param storageAccountsku string = 'Standard_LRS'

@description('Location for all resources.')
param location string = resourceGroup().location

var storageAccountName = '${uniqueString(resourceGroup().id)}storage'

resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {
  name: storageAccountName
  location: location
  sku: {
    name: storageAccountsku
  }
  kind: 'StorageV2'
  tags: {
    ObjectName: storageAccountName
  }
  properties: {
    minimumTlsVersion: 'TLS1_2'
    allowBlobPublicAccess: false
    networkAcls: {
      defaultAction: 'Deny'
    }
    supportsHttpsTrafficOnly: true
  }
}

resource batchAccount 'Microsoft.Batch/batchAccounts@2024-02-01' = {
  name: batchAccountName
  location: location
  tags: {
    ObjectName: batchAccountName
  }
  properties: {
    autoStorage: {
      storageAccountId: storageAccount.id
    }
  }
}

output storageAccountName string = storageAccount.name
output batchAccountName string = batchAccount.name
output location string = location
output resourceGroupName string = resourceGroup().name
output resourceId string = batchAccount.id

该 Bicep 文件中定义了两个 Azure 资源:

部署 Bicep 文件

  1. 将该 Bicep 文件另存为本地计算机上的 main.bicep。

  2. 使用 Azure CLI 或 Azure PowerShell 来部署该 Bicep 文件。

    az group create --name exampleRG --location eastus
    az deployment group create --resource-group exampleRG --template-file main.bicep
    

    部署完成后,应会看到一条指出部署成功的消息。

验证部署

使用 Azure 门户、Azure CLI 或 Azure PowerShell 列出资源组中已部署的资源。

az resource list --resource-group exampleRG

清理资源

如果你打算继续学习其他教程,可以保留这些资源。 如果不再需要资源组及其所有资源,请使用 Azure 门户、Azure CLI 或 Azure PowerShell 将其删除。

az group delete --name exampleRG

后续步骤

在本快速入门中,你已使用 Bicep 创建了 Batch 帐户和存储帐户。 若要详细了解 Azure Batch,请继续学习 Azure Batch 教程。