|
| 1 | +--- |
| 2 | +title: Quickstart - Create an Azure Cosmos DB and a container by using Azure Resource Manager template |
| 3 | +description: Quickstart showing how to an Azure Cosmos database and a container by using Azure Resource Manager template |
| 4 | +author: SnehaGunda |
| 5 | +ms.author: sngun |
| 6 | +tags: azure-resource-manager |
| 7 | +ms.service: cosmos-db |
| 8 | +ms.topic: quickstart |
| 9 | +ms.date: 01/21/2020 |
| 10 | +#Customer intent: As a database admin who is new to Azure, I want to use Azure Cosmos DB to store and manage my data. |
| 11 | + |
| 12 | +--- |
| 13 | + |
| 14 | +# Quickstart: Create an Azure Cosmos DB and a container by using Azure Resource Manager template |
| 15 | + |
| 16 | +Azure Cosmos DB is Microsoft’s globally distributed multi-model database service. You can use Azure Cosmos DB to quickly create and query key/value databases, document databases, and graph databases. This quickstart focuses on the process of deploying a Resource Manager template to create an Azure Cosmos database and a container within that database. You can later store data in this container. |
| 17 | + |
| 18 | +[Resource Manager template](../azure-resource-manager/templates/overview.md) is a JavaScript Object Notation (JSON) file that defines the infrastructure and configuration for your project. The template uses declarative syntax, which lets you state what you intend to deploy without having to write the sequence of programming commands to create it. If you want to learn more about developing Resource Manager templates, see [Resource Manager documentation](/azure/azure-resource-manager/) and the [template reference](/azure/templates/microsoft.DocumentDB/allversions). |
| 19 | + |
| 20 | +If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/free/?WT.mc_id=A261C142F) before you begin. |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +An Azure subscription or free Azure Cosmos DB trial account |
| 25 | + |
| 26 | +- [!INCLUDE [quickstarts-free-trial-note](../../includes/quickstarts-free-trial-note.md)] |
| 27 | + |
| 28 | +- [!INCLUDE [cosmos-db-emulator-docdb-api](../../includes/cosmos-db-emulator-docdb-api.md)] |
| 29 | + |
| 30 | +## Create an Azure Cosmos account, database, container |
| 31 | + |
| 32 | +The template used in this quickstart is from [Azure Quickstart templates](https://azure.microsoft.com/resources/templates/101-cosmosdb-create/). |
| 33 | + |
| 34 | +[!code-json[<Resource Manager template create Azure Cosmos DB>](~/quickstart-templates/101-cosmosdb-create/azuredeploy.json)] |
| 35 | + |
| 36 | +Three Azure resources are defined in the template: |
| 37 | + |
| 38 | +* [Microsoft.DocumentDB/databaseAccounts](/azure/templates/microsoft.documentdb/databaseaccounts): Create an Azure Cosmos account. |
| 39 | + |
| 40 | +* [Microsoft.DocumentDB/databaseAccounts/sqlDatabases](/azure/templates/microsoft.documentdb/databaseaccounts/sqldatabases): Create an Azure Cosmos database. |
| 41 | + |
| 42 | +* [Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers](/azure/templates/microsoft.documentdb/databaseaccounts/sqldatabases/containers): Create an Azure Cosmos container. |
| 43 | + |
| 44 | +More Azure Cosmos DB template samples can be found in the [quickstart template gallery](https://azure.microsoft.com/resources/templates/?resourceType=Microsoft.Documentdb). |
| 45 | + |
| 46 | +1. Select the following image to sign in to Azure and open a template. The template creates an Azure Cosmos account, a database, and a container. |
| 47 | + |
| 48 | + <a href="https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2FAzure%2Fazure-quickstart-templates%2Fmaster%2F101-cosmosdb-create%2Fazuredeploy.json"><img src="./media/quick-create-template/deploy-to-azure.png" alt="deploy to azure"/></a> |
| 49 | + |
| 50 | +2. Select or enter the following values. |
| 51 | + |
| 52 | +  |
| 53 | + |
| 54 | + Unless it is specified, use the default values to create the Azure Cosmos resources. |
| 55 | + |
| 56 | + * **Subscription**: select an Azure subscription. |
| 57 | + * **Resource group**: select **Create new**, enter a unique name for the resource group, and then click **OK**. |
| 58 | + * **Location**: select a location. For example, **Central US**. |
| 59 | + * **Account Name**: enter a name for the Azure Cosmos account. It must be globally unique. |
| 60 | + * **Location**: enter a location where you want to create your Azure Cosmos account. The Azure Cosmos account can be in the same location as the resource group. |
| 61 | + * **Primary Region**: The primary replica region for the Azure Cosmos account. |
| 62 | + * **Secondary region**: The secondary replica region for the Azure Cosmos account. |
| 63 | + * **Database Name**: The name of the Azure Cosmos database. |
| 64 | + * **Container Name**: The name of the Azure Cosmos container. |
| 65 | + * **Throughput**: The throughput for the container, minimum throughput value is 400 RU/s. |
| 66 | + * **I agree to the terms and conditions state above**: Select. |
| 67 | + |
| 68 | +3. Select **Purchase**. After the Azure Cosmos account has been deployed successfully, you get a notification: |
| 69 | + |
| 70 | +  |
| 71 | + |
| 72 | +The Azure portal is used to deploy the template. In addition to the Azure portal, you can also use the Azure PowerShell, Azure CLI, and REST API. To learn other deployment methods, see [Deploy templates](../azure-resource-manager/templates/deploy-powershell.md). |
| 73 | + |
| 74 | +## Validate the deployment |
| 75 | + |
| 76 | +You can either use the Azure portal to check the Azure Cosmos account, the database, and the container or use the following Azure CLI or Azure PowerShell script to list the secret created. |
| 77 | + |
| 78 | +# [CLI](#tab/CLI) |
| 79 | + |
| 80 | +```azurecli-interactive |
| 81 | +echo "Enter your Azure Cosmos account name:" && |
| 82 | +read cosmosAccountName && |
| 83 | +echo "Enter the resource group where the Azure Cosmos account exists:" && |
| 84 | +read resourcegroupName && |
| 85 | +az cosmosdb show -g $resourcegroupName -n $cosmosAccountName |
| 86 | +``` |
| 87 | + |
| 88 | +# [PowerShell](#tab/PowerShell) |
| 89 | + |
| 90 | +```azurepowershell-interactive |
| 91 | +$resourceGroupName = Read-Host -Prompt "Enter the resource group name where your Azure Cosmos account exists" |
| 92 | +(Get-AzResource -ResourceType "Microsoft.DocumentDB/databaseAccounts" -ResourceGroupName $resourceGroupName).Name |
| 93 | + Write-Host "Press [ENTER] to continue..." |
| 94 | +``` |
| 95 | + |
| 96 | +--- |
| 97 | + |
| 98 | +## Clean up resources |
| 99 | + |
| 100 | +If you plan to continue on to work with subsequent and tutorials, you may wish to leave these resources in place. |
| 101 | +When no longer needed, delete the resource group, which deletes the Azure Cosmos account and the related resources. To delete the resource group by using Azure CLI or Azure Powershell: |
| 102 | + |
| 103 | +# [CLI](#tab/CLI) |
| 104 | + |
| 105 | +```azurecli-interactive |
| 106 | +echo "Enter the Resource Group name:" && |
| 107 | +read resourceGroupName && |
| 108 | +az group delete --name $resourceGroupName && |
| 109 | +echo "Press [ENTER] to continue ..." |
| 110 | +``` |
| 111 | + |
| 112 | +# [PowerShell](#tab/PowerShell) |
| 113 | + |
| 114 | +```azurepowershell-interactive |
| 115 | +$resourceGroupName = Read-Host -Prompt "Enter the Resource Group name" |
| 116 | +Remove-AzResourceGroup -Name $resourceGroupName |
| 117 | +Write-Host "Press [ENTER] to continue..." |
| 118 | +``` |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +## Next steps |
| 123 | + |
| 124 | +In this quickstart, you created an Azure Cosmos account, a database and a container by using an Azure Resource Manager template and validated the deployment. To learn more about Azure Cosmos DB and Azure Resource Manager, continue on to the articles below. |
| 125 | + |
| 126 | +- Read an [Overview of Azure Cosmos DB](introduction.md) |
| 127 | +- Learn more about [Azure Resource Manager](../azure-resource-manager/management/overview.md) |
| 128 | +- Get other [Azure Cosmos DB Resource Manager templates](resource-manager-samples.md) |
0 commit comments