使用 Bicep 管理 Azure Cosmos DB for Apache Cassandra 資源
適用於: Cassandra
在本文中,您將了解如何使用 Bicep 來部署及管理您的 Azure Cosmos DB for Apache Cassandra 帳戶、keyspace 和資料表。
本文說明 API for Cassandra 帳戶的 Bicep 範例。 您也可以找到適用於 SQL、Gremlin、MongoDB 和資料表 API 的 Bicep 範例。
重要
- 帳戶名稱限制為 44 個字元,全部小寫。
- 若要變更輸送量值,請使用已更新的 RU/秒重新部署範本。
- 您在新增或移除 Azure Cosmos DB 帳戶的位置時,無法同時修改其他屬性。 這些作業必須個別執行。
若要建立下列任何 Azure Cosmos DB 資源,請將下列範例複製到新的 Bicep 檔案中。 當您使用不同的名稱和值來部署相同資源的多個執行個體時,可以選擇建立參數檔案以供使用。 部署 Azure Resource Manager 範本的方式有很多種,包括 Azure CLI、Azure PowerShell 和 Cloud Shell。
具有可自動調整佈建輸送量的 API for Cassandra
在兩個區域中建立 Azure Cosmos DB 帳戶 (具有一致性和容錯移轉選項),且 keyspace 和資料表已設定自動調整輸送量。
@description('Cosmos DB account name, max length 44 characters')
param accountName string = 'cassandra-${uniqueString(resourceGroup().id)}'
@description('Location for the Cosmos DB account.')
param location string = resourceGroup().location
@description('The primary replica region for the Cosmos DB account.')
param primaryRegion string
@description('The secondary replica region for the Cosmos DB account.')
param secondaryRegion string
@allowed([
'Eventual'
'ConsistentPrefix'
'Session'
'BoundedStaleness'
'Strong'
])
@description('The default consistency level of the Cosmos DB account.')
param defaultConsistencyLevel string = 'Eventual'
@minValue(10)
@maxValue(1000000)
@description('Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2,147,483,647. Multi Region: 100,000 to 2,147,483,647.')
param maxStalenessPrefix int = 100000
@minValue(5)
@maxValue(86400)
@description('Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84,600. Multi Region: 300 to 86,400.')
param maxIntervalInSeconds int = 300
@allowed([
true
false
])
@description('Enable system managed failover for regions')
param systemManagedFailover bool = true
@description('The name for the Cassandra Keyspace')
param keyspaceName string
@description('The name for the Cassandra table')
param tableName string
@minValue(1000)
@maxValue(1000000)
@description('Maximum autoscale throughput for the Cassandra table')
param autoscaleMaxThroughput int = 1000
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: 'EnableCassandra'
}
]
consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
locations: locations
databaseAccountOfferType: 'Standard'
enableAutomaticFailover: systemManagedFailover
}
}
resource keyspace 'Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces@2022-05-15' = {
name: '${account.name}/${keyspaceName}'
properties: {
resource: {
id: keyspaceName
}
}
}
resource table 'Microsoft.DocumentDb/databaseAccounts/cassandraKeyspaces/tables@2022-05-15' = {
name: '${keyspace.name}/${tableName}'
properties: {
resource: {
id: tableName
schema: {
columns: [
{
name: 'loadid'
type: 'uuid'
}
{
name: 'machine'
type: 'uuid'
}
{
name: 'cpu'
type: 'int'
}
{
name: 'mtime'
type: 'int'
}
{
name: 'load'
type: 'float'
}
]
partitionKeys: [
{
name: 'machine'
}
{
name: 'cpu'
}
{
name: 'mtime'
}
]
clusterKeys: [
{
name: 'loadid'
orderBy: 'asc'
}
]
}
}
options: {
autoscaleSettings: {
maxThroughput: autoscaleMaxThroughput
}
}
}
}
具有標準佈建輸送量的 API for Cassandra
在兩個區域中建立 Azure Cosmos DB 帳戶 (具有一致性和容錯移轉選項),且 keyspace 和資料表已設定標準輸送量。
@description('Cosmos DB account name, max length 44 characters')
param accountName string = 'cassandra-${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
@allowed([
'Eventual'
'ConsistentPrefix'
'Session'
'BoundedStaleness'
'Strong'
])
@description('The default consistency level of the Cosmos DB account.')
param defaultConsistencyLevel string = 'Session'
@minValue(10)
@maxValue(2147483647)
@description('Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 2,147,483,647. Multi Region: 100,000 to 2,147,483,647.')
param maxStalenessPrefix int = 100000
@minValue(5)
@maxValue(86400)
@description('Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400.')
param maxIntervalInSeconds int = 300
@allowed([
true
false
])
@description('Enable system managed failover for regions')
param systemManagedFailover bool = true
@description('The name for the Cassandra Keyspace')
param keyspaceName string
@description('The name for the Cassandra table')
param tableName string
@minValue(400)
@maxValue(1000000)
@description('The throughput for Cassandra 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: 'EnableCassandra'
}
]
consistencyPolicy: consistencyPolicy[defaultConsistencyLevel]
locations: locations
databaseAccountOfferType: 'Standard'
enableAutomaticFailover: systemManagedFailover
}
}
resource keyspace 'Microsoft.DocumentDB/databaseAccounts/cassandraKeyspaces@2022-05-15' = {
name: '${account.name}/${keyspaceName}'
properties: {
resource: {
id: keyspaceName
}
}
}
resource table 'Microsoft.DocumentDb/databaseAccounts/cassandraKeyspaces/tables@2022-05-15' = {
name: '${keyspace.name}/${tableName}'
properties: {
resource: {
id: tableName
schema: {
columns: [
{
name: 'loadid'
type: 'uuid'
}
{
name: 'machine'
type: 'uuid'
}
{
name: 'cpu'
type: 'int'
}
{
name: 'mtime'
type: 'int'
}
{
name: 'load'
type: 'float'
}
]
partitionKeys: [
{
name: 'machine'
}
{
name: 'cpu'
}
{
name: 'mtime'
}
]
clusterKeys: [
{
name: 'loadid'
orderBy: 'asc'
}
]
}
options: {
throughput: throughput
}
}
}
}
下一步
以下是一些額外資源: