Create an Azure Cosmos DB account in multiple regions

Last updated: 4/25/2019

This template creates an Azure Cosmos DB account for any API Type with a primary and secondary region with choice of consistency level and options to enable multi-master and Failover Type.

This Azure Resource Manager template was created by a member of the community and not by Microsoft. Each Resource Manager template is licensed to you under a license agreement by its owner, not Microsoft. Microsoft is not responsible for Resource Manager templates provided and licensed by community members and does not screen for security, compatibility, or performance. Community Resource Manager templates are not supported under any Microsoft support program or service, and are made available AS IS without warranty of any kind.

Parameters

Parameter Name Description
accountName Cosmos DB account name
location Location for the Cosmos DB account.
primaryRegion The primary replica region for the Cosmos DB account.
secondaryRegion The secondary replica region for the Cosmos DB account.
api Cosmos DB account type.
defaultConsistencyLevel The default consistency level of the Cosmos DB account.
maxStalenessPrefix Max stale requests. Required for BoundedStaleness. Valid ranges, Single Region: 10 to 1000000. Multi Region: 100000 to 1000000.
maxIntervalInSeconds Max lag time (seconds). Required for BoundedStaleness. Valid ranges, Single Region: 5 to 84600. Multi Region: 300 to 86400.
multipleWriteLocations Enable multi-master to make all regions writable.
automaticFailover Enable automatic failover for regions. Ignored when Multi-Master is enabled

Use the template

PowerShell

New-AzResourceGroup -Name <resource-group-name> -Location <resource-group-location> #use this command when you need to create a new resource group for your deployment
New-AzResourceGroupDeployment -ResourceGroupName <resource-group-name> -TemplateUri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-cosmosdb-create-multi-region-account/azuredeploy.json
Install and configure Azure PowerShell

Command line

az group create --name <resource-group-name> --location <resource-group-location> #use this command when you need to create a new resource group for your deployment
az group deployment create --resource-group <my-resource-group> --template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-cosmosdb-create-multi-region-account/azuredeploy.json
Install and Configure the Azure Cross-Platform Command-Line Interface