CosmosDB Global Distribution Configuration
Syntax
az cosmosdb update --name <name-of-cosmosdb-account> \
--resource-group <resource-group-name> \
--locations regionName=writeLocation writable=true \
--locations regionName=readLocation writable=false
Example
az cosmosdb update --name MyCosmosDB --resource-group MyResourceGroup \
--locations regionName=East US writable=true \
--locations regionName=West US writable=false
Output
{
"capabilities": [],
"consistencyPolicy": {
"defaultConsistencyLevel": "Session",
"maxStalenessPrefix": 100
},
"databaseAccountOfferType": "Standard",
"documentEndpoint": "https://mycosmosdb.documents.azure.com:443/",
"enableAutomaticFailover": true,
"id": "/subscriptions/7cd9d26c-36d61-4e57-8a60-0f40767b4c6e/resourceGroups/MyResourceGroup/providers/Microsoft.DocumentDb/databaseAccounts/MyCosmosDB",
"ipRangeFilter": "",
"kind": "GlobalDocumentDB",
"locations": [
{
"documentEndpoint": "https://mycosmosdb-brazilcentral.documents.azure.com:443/",
"failoverPriority": 0,
"locationName": "Brazil South",
"readEndpoint": "https://mycosmosdb-brazilcentral.documents.azure.com:443/",
"region": "Brazil South",
"status": "Available",
"writableEndpoint": "https://mycosmosdb-brazilcentral.documents.azure.com:443/"
},
{
"documentEndpoint": "https://mycosmosdb-eastus.documents.azure.com:443/",
"failoverPriority": 1,
"locationName": "East US",
"readEndpoint": "https://mycosmosdb-eastus.documents.azure.com:443/",
"region": "East US",
"status": "Available",
"writableEndpoint": "https://mycosmosdb-eastus.documents.azure.com:443/"
},
{
"documentEndpoint": "https://mycosmosdb-westus2.documents.azure.com:443/",
"failoverPriority": 2,
"locationName": "West US 2",
"readEndpoint": "https://mycosmosdb-westus2.documents.azure.com:443/",
"region": "West US 2",
"status": "Available",
"writableEndpoint": "https://mycosmosdb-westus2.documents.azure.com:443/"
}
],
"name": "MyCosmosDB",
"provisioningState": "Succeeded",
"readLocations": [
{
"documentEndpoint": "https://mycosmosdb-brazilcentral.documents.azure.com:443/",
"failoverPriority": 0,
"locationName": "Brazil South",
"readEndpoint": "https://mycosmosdb-brazilcentral.documents.azure.com:443/",
"region": "Brazil South",
"status": "Available",
"writableEndpoint": "https://mycosmosdb-brazilcentral.documents.azure.com:443/"
},
{
"documentEndpoint": "https://mycosmosdb-eastus.documents.azure.com:443/",
"failoverPriority": 1,
"locationName": "East US",
"readEndpoint": "https://mycosmosdb-eastus.documents.azure.com:443/",
"region": "East US",
"status": "Available",
"writableEndpoint": "https://mycosmosdb-eastus.documents.azure.com:443/"
},
{
"documentEndpoint": "https://mycosmosdb-westus2.documents.azure.com:443/",
"failoverPriority": 2,
"locationName": "West US 2",
"readEndpoint": "https://mycosmosdb-westus2.documents.azure.com:443/",
"region": "West US 2",
"status": "Available",
"writableEndpoint": "https://mycosmosdb-westus2.documents.azure.com:443/"
}
],
"resourceGroup": "MyResourceGroup",
"tags": {},
"type": "Microsoft.DocumentDb/databaseAccounts"
}
Explanation
CosmosDB is a globally distributed, multi-model database service. It allows you to distribute your data across multiple regions to achieve high availability, low-latency access to data and disaster recovery.
This command helps set the global distribution configuration for CosmosDB. The command takes in the name of the CosmosDB account, the resource group where it is located, and the read and write regions.
The --locations
flag indicates the write location for the CosmosDB account. The writable
flag is set to true
indicating that the region is writable. You can specify multiple write locations.
The --locations
flag indicates the read locations for the CosmosDB account. The writable
flag is set to false
indicating that the regions are read-only. You can specify multiple read locations.
Use
This command can be used when setting up a new CosmosDB account or updating the global distribution configuration for an existing account.
Important Points
- CosmosDB is a globally distributed, multi-model database service
- The
--locations
flag indicates the write and read regions for the CosmosDB account - You can specify multiple write and read regions
- The
writable
flag is set totrue
for write region andfalse
for read regions - The command can be used to update the global distribution configuration for an existing account
Summary
This command allows you to configure the global distribution settings for CosmosDB. You can specify the write and read regions and their respective writable
flags. Setting up the global configuration for CosmosDB will ensure high availability, low-latency access to data and disaster recovery.