Share via


Bicep kullanarak Tablo kaynakları için Azure Cosmos DB'i yönetme

ŞUNLAR IÇIN GEÇERLIDIR: Tablo

Bu makalede, Tablo hesapları ve tabloları için Azure Cosmos DB'nizi dağıtmaya ve yönetmeye yardımcı olması için Bicep'i kullanmayı öğreneceksiniz.

Bu makalede yalnızca Tablo hesapları için API örnekleri verilmiştir. Cassandra, Gremlin, MongoDB, SQL makaleleri için Bicep örneklerini de bulabilirsiniz.

Önemli

  • Hesap adları, tümü küçük harfle olmak üzere 44 karakterle sınırlıdır.
  • Aktarım hızı değerlerini değiştirmek için şablonu güncelleştirilmiş RU/sn ile yeniden dağıtın.
  • Azure Cosmos DB hesabına konum eklediğinizde veya kaldırdığınızda, diğer özellikleri aynı anda değiştiremezsiniz. Bu işlemlerin ayrı olarak yapılması gerekir.

Aşağıdaki Azure Cosmos DB kaynaklarından herhangi birini oluşturmak için aşağıdaki örneği yeni bir bicep dosyasına kopyalayın. İsteğe bağlı olarak, aynı kaynağın farklı adlara ve değerlere sahip birden çok örneğini dağıtırken kullanılacak bir parametre dosyası oluşturabilirsiniz. Azure CLI, Azure PowerShell ve Cloud Shell dahil olmak üzere AzureResource Manager şablonlarını dağıtmanın birçok yolu vardır.

İpucu

Tablo api'sini kullanırken paylaşılan aktarım hızını etkinleştirmek için Azure portal hesap düzeyinde aktarım hızını etkinleştirin. Hesap düzeyinde paylaşılan aktarım hızı Bicep kullanılarak ayarlanamaz.

Otomatik ölçeklendirme aktarım hızına sahip Tablo için Azure Cosmos DB hesabı

Otomatik ölçeklendirme aktarım hızına sahip tek bir tabloyla Tablo için API için bir Azure Cosmos DB hesabı oluşturun.

@description('Cosmos DB account name')
param accountName string = 'table-${uniqueString(resourceGroup().id)}'

@description('Location for the Cosmos DB account.')
param location string = resourceGroup().location

@description('The primary region for the Cosmos DB account.')
param primaryRegion string

@description('The secondary region for the Cosmos DB account.')
param secondaryRegion string

@description('The default consistency level of the Cosmos DB account.')
@allowed([
  'Eventual'
  'ConsistentPrefix'
  'Session'
  'BoundedStaleness'
  'Strong'
])
param defaultConsistencyLevel string = 'Session'

@description('Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2147483647. Multi Region: 100000 to 2147483647.')
@minValue(10)
@maxValue(2147483647)
param maxStalenessPrefix int = 100000

@description('Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400.')
@minValue(5)
@maxValue(86400)
param maxIntervalInSeconds int = 300

@description('Enable system managed failover for regions')
param systemManagedFailover bool = true

@description('The name for the table')
param tableName string

@description('Maximum autoscale throughput for the table')
@minValue(1000)
@maxValue(1000000)
param autoscaleMaxThroughput int = 4000

var consistencyPolicy = {
  Eventual: {
    defaultConsistencyLevel: 'Eventual'
  }
  ConsistentPrefix: {
    defaultConsistencyLevel: 'ConsistentPrefix'
  }
  Session: {
    defaultConsistencyLevel: 'Session'
  }
  BoundedStaleness: {
    defaultConsistencyLevel: 'BoundedStaleness'
    maxStalenessPrefix: maxStalenessPrefix
    maxIntervalInSeconds: maxIntervalInSeconds
  }
  Strong: {
    defaultConsistencyLevel: 'Strong'
  }
}
var locations = [
  {
    locationName: primaryRegion
    failoverPriority: 0
    isZoneRedundant: false
  }
  {
    locationName: secondaryRegion
    failoverPriority: 1
    isZoneRedundant: false
  }
]

resource account 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = {
  name: toLower(accountName)
  location: location
  kind: 'GlobalDocumentDB'
  properties: {
    capabilities: [
      {
        name: 'EnableTable'
      }
    ]
    consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
    locations: locations
    databaseAccountOfferType: 'Standard'
    enableAutomaticFailover: systemManagedFailover
  }
}

resource table 'Microsoft.DocumentDB/databaseAccounts/tables@2022-05-15' = {
  parent: account
  name: tableName
  properties: {
    resource: {
      id: tableName
    }
    options: {
      autoscaleSettings: {
        maxThroughput: autoscaleMaxThroughput
      }
    }
  }
}

Standart sağlanan aktarım hızına sahip Tablo için Azure Cosmos DB hesabı

Standart aktarım hızına sahip tek bir tabloyla Tablo api'si için bir Azure Cosmos DB hesabı oluşturun.

@description('Cosmos DB account name')
param accountName string = 'table-${uniqueString(resourceGroup().id)}'

@description('Location for the Cosmos DB account.')
param location string = resourceGroup().location

@description('The primary region for the Cosmos DB account.')
param primaryRegion string

@description('The secondary region for the Cosmos DB account.')
param secondaryRegion string

@description('The default consistency level of the Cosmos DB account.')
@allowed([
  'Eventual'
  'ConsistentPrefix'
  'Session'
  'BoundedStaleness'
  'Strong'
])
param defaultConsistencyLevel string = 'Session'

@description('Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2147483647. Multi Region: 100000 to 2147483647.')
@minValue(10)
@maxValue(2147483647)
param maxStalenessPrefix int = 100000

@description('Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400.')
@minValue(5)
@maxValue(86400)
param maxIntervalInSeconds int = 300

@description('Enable system managed failover for regions')
param systemManagedFailover bool = true

@description('The name for the table')
param tableName string

@minValue(400)
@maxValue(1000000)
@description('The throughput for the table')
param throughput int = 400

var consistencyPolicy = {
  Eventual: {
    defaultConsistencyLevel: 'Eventual'
  }
  ConsistentPrefix: {
    defaultConsistencyLevel: 'ConsistentPrefix'
  }
  Session: {
    defaultConsistencyLevel: 'Session'
  }
  BoundedStaleness: {
    defaultConsistencyLevel: 'BoundedStaleness'
    maxStalenessPrefix: maxStalenessPrefix
    maxIntervalInSeconds: maxIntervalInSeconds
  }
  Strong: {
    defaultConsistencyLevel: 'Strong'
  }
}
var locations = [
  {
    locationName: primaryRegion
    failoverPriority: 0
    isZoneRedundant: false
  }
  {
    locationName: secondaryRegion
    failoverPriority: 1
    isZoneRedundant: false
  }
]

resource account 'Microsoft.DocumentDB/databaseAccounts@2022-05-15' = {
  name: toLower(accountName)
  location: location
  kind: 'GlobalDocumentDB'
  properties: {
    capabilities: [
      {
        name: 'EnableTable'
      }
    ]
    consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
    locations: locations
    databaseAccountOfferType: 'Standard'
    enableAutomaticFailover: systemManagedFailover
  }
}

resource table 'Microsoft.DocumentDB/databaseAccounts/tables@2022-05-15' = {
  parent: account
  name: tableName
  properties: {
    resource: {
      id: tableName
    }
    options: {
      throughput: throughput
    }
  }
}

Sonraki adımlar

Aşağıdaki ek kaynakları da inceleyebilirsiniz: