|
| 1 | +--- |
| 2 | + title: include file |
| 3 | + description: include file |
| 4 | + services: cosmos-db |
| 5 | + author: seesharprun |
| 6 | + ms.service: cosmos-db |
| 7 | + ms.topic: include |
| 8 | + ms.date: 09/15/2022 |
| 9 | + ms.author: sidandrews |
| 10 | +ms.reviewer: mjbrown |
| 11 | + ms.custom: include file |
| 12 | +--- |
| 13 | + |
| 14 | + |
| 15 | +This quickstart will create a single Azure Cosmos DB account using the SQL API. |
| 16 | + |
| 17 | +#### [Azure CLI](#tab/azure-cli) |
| 18 | + |
| 19 | +1. Create shell variables for *accountName*, *resourceGroupName*, and *location*. |
| 20 | + |
| 21 | + ```azurecli-interactive |
| 22 | + # Variable for resource group name |
| 23 | + resourceGroupName="msdocs-cosmos-quickstart-rg" |
| 24 | + location="westus" |
| 25 | +
|
| 26 | + # Variable for account name with a randomly generated suffix |
| 27 | + let suffix=$RANDOM*$RANDOM |
| 28 | + accountName="msdocs-$suffix" |
| 29 | + ``` |
| 30 | +
|
| 31 | +1. If you haven't already, sign in to the Azure CLI using the [``az login``](/cli/azure/reference-index#az-login) command. |
| 32 | +
|
| 33 | +1. Use the [``az group create``](/cli/azure/group#az-group-create) command to create a new resource group in your subscription. |
| 34 | +
|
| 35 | + ```azurecli-interactive |
| 36 | + az group create \ |
| 37 | + --name $resourceGroupName \ |
| 38 | + --location $location |
| 39 | + ``` |
| 40 | +
|
| 41 | +1. Use the [``az cosmosdb create``](/cli/azure/cosmosdb#az-cosmosdb-create) command to create a new Azure Cosmos DB SQL API account with default settings. |
| 42 | +
|
| 43 | + ```azurecli-interactive |
| 44 | + az cosmosdb create \ |
| 45 | + --resource-group $resourceGroupName \ |
| 46 | + --name $accountName \ |
| 47 | + --locations regionName=$location |
| 48 | + ``` |
| 49 | +
|
| 50 | +1. Get the SQL API endpoint *URI* for the account using the [``az cosmosdb show``](/cli/azure/cosmosdb#az-cosmosdb-show) command. |
| 51 | +
|
| 52 | + ```azurecli-interactive |
| 53 | + az cosmosdb show \ |
| 54 | + --resource-group $resourceGroupName \ |
| 55 | + --name $accountName \ |
| 56 | + --query "documentEndpoint" |
| 57 | + ``` |
| 58 | +
|
| 59 | +1. Find the *PRIMARY KEY* from the list of keys for the account with the [`az-cosmosdb-keys-list`](/cli/azure/cosmosdb/keys#az-cosmosdb-keys-list) command. |
| 60 | +
|
| 61 | + ```azurecli-interactive |
| 62 | + az cosmosdb keys list \ |
| 63 | + --resource-group $resourceGroupName \ |
| 64 | + --name $accountName \ |
| 65 | + --type "keys" \ |
| 66 | + --query "primaryMasterKey" |
| 67 | + ``` |
| 68 | +
|
| 69 | +1. Record the *URI* and *PRIMARY KEY* values. You'll use these credentials later. |
| 70 | +
|
| 71 | +#### [PowerShell](#tab/azure-powershell) |
| 72 | +
|
| 73 | +1. Create shell variables for *ACCOUNT_NAME*, *RESOURCE_GROUP_NAME*, and **LOCATION**. |
| 74 | +
|
| 75 | + ```azurepowershell-interactive |
| 76 | + # Variable for resource group name |
| 77 | + $RESOURCE_GROUP_NAME = "msdocs-cosmos-quickstart-rg" |
| 78 | + $LOCATION = "West US" |
| 79 | + |
| 80 | + # Variable for account name with a randomly generated suffix |
| 81 | + $SUFFIX = Get-Random |
| 82 | + $ACCOUNT_NAME = "msdocs-$SUFFIX" |
| 83 | + ``` |
| 84 | +
|
| 85 | +1. If you haven't already, sign in to Azure PowerShell using the [``Connect-AzAccount``](/powershell/module/az.accounts/connect-azaccount) cmdlet. |
| 86 | +
|
| 87 | +1. Use the [``New-AzResourceGroup``](/powershell/module/az.resources/new-azresourcegroup) cmdlet to create a new resource group in your subscription. |
| 88 | +
|
| 89 | + ```azurepowershell-interactive |
| 90 | + $parameters = @{ |
| 91 | + Name = $RESOURCE_GROUP_NAME |
| 92 | + Location = $LOCATION |
| 93 | + } |
| 94 | + New-AzResourceGroup @parameters |
| 95 | + ``` |
| 96 | +
|
| 97 | +1. Use the [``New-AzCosmosDBAccount``](/powershell/module/az.cosmosdb/new-azcosmosdbaccount) cmdlet to create a new Azure Cosmos DB SQL API account with default settings. |
| 98 | +
|
| 99 | + ```azurepowershell-interactive |
| 100 | + $parameters = @{ |
| 101 | + ResourceGroupName = $RESOURCE_GROUP_NAME |
| 102 | + Name = $ACCOUNT_NAME |
| 103 | + Location = $LOCATION |
| 104 | + } |
| 105 | + New-AzCosmosDBAccount @parameters |
| 106 | + ``` |
| 107 | +
|
| 108 | +1. Get the SQL API endpoint *URI* for the account using the [``Get-AzCosmosDBAccount``](/powershell/module/az.cosmosdb/get-azcosmosdbaccount) cmdlet. |
| 109 | +
|
| 110 | + ```azurepowershell-interactive |
| 111 | + $parameters = @{ |
| 112 | + ResourceGroupName = $RESOURCE_GROUP_NAME |
| 113 | + Name = $ACCOUNT_NAME |
| 114 | + } |
| 115 | + Get-AzCosmosDBAccount @parameters | |
| 116 | + Select-Object -Property "DocumentEndpoint" |
| 117 | + ``` |
| 118 | +
|
| 119 | +1. Find the *PRIMARY KEY* from the list of keys for the account with the [``Get-AzCosmosDBAccountKey``](/powershell/module/az.cosmosdb/get-azcosmosdbaccountkey) cmdlet. |
| 120 | +
|
| 121 | + ```azurepowershell-interactive |
| 122 | + $parameters = @{ |
| 123 | + ResourceGroupName = $RESOURCE_GROUP_NAME |
| 124 | + Name = $ACCOUNT_NAME |
| 125 | + Type = "Keys" |
| 126 | + } |
| 127 | + Get-AzCosmosDBAccountKey @parameters | |
| 128 | + Select-Object -Property "PrimaryMasterKey" |
| 129 | + ``` |
| 130 | +
|
| 131 | +1. Record the *URI* and *PRIMARY KEY* values. You'll use these credentials later. |
| 132 | +
|
| 133 | +#### [Portal](#tab/azure-portal) |
| 134 | +
|
| 135 | +> [!TIP] |
| 136 | +> For this quickstart, we recommend using the resource group name ``msdocs-cosmos-quickstart-rg``. |
| 137 | +
|
| 138 | +1. Sign in to the [Azure portal](https://portal.azure.com). |
| 139 | +
|
| 140 | +1. From the Azure portal menu or the **Home page**, select **Create a resource**. |
| 141 | +
|
| 142 | +1. On the **New** page, search for and select **Azure Cosmos DB**. |
| 143 | +
|
| 144 | +1. On the **Select API option** page, select the **Create** option within the **Core (SQL) - Recommend** section. Azure Cosmos DB has five APIs: SQL, MongoDB, Gremlin, Table, and Cassandra. [Learn more about the SQL API](../index.yml). |
| 145 | +
|
| 146 | + :::image type="content" source="../media/create-account-portal/cosmos-api-choices.png" lightbox="../media/create-account-portal/cosmos-api-choices.png" alt-text="Screenshot of select API option page for Azure Cosmos DB."::: |
| 147 | +
|
| 148 | +1. On the **Create Azure Cosmos DB Account** page, enter the following information: |
| 149 | +
|
| 150 | + | Setting | Value | Description | |
| 151 | + | --- | --- | --- | |
| 152 | + | Subscription | Subscription name | Select the Azure subscription that you wish to use for this Azure Cosmos account. | |
| 153 | + | Resource Group | Resource group name | Select a resource group, or select **Create new**, then enter a unique name for the new resource group. | |
| 154 | + | Account Name | A unique name | Enter a name to identify your Azure Cosmos account. The name will be used as part of a fully qualified domain name (FQDN) with a suffix of *documents.azure.com*, so the name must be globally unique. The name can only contain lowercase letters, numbers, and the hyphen (-) character. The name must also be between 3-44 characters in length. | |
| 155 | + | Location | The region closest to your users | Select a geographic location to host your Azure Cosmos DB account. Use the location that is closest to your users to give them the fastest access to the data. | |
| 156 | + | Capacity mode |Provisioned throughput or Serverless|Select **Provisioned throughput** to create an account in [provisioned throughput](../../set-throughput.md) mode. Select **Serverless** to create an account in [serverless](../../serverless.md) mode. | |
| 157 | + | Apply Azure Cosmos DB free tier discount | **Apply** or **Do not apply** |With Azure Cosmos DB free tier, you'll get the first 1000 RU/s and 25 GB of storage for free in an account. Learn more about [free tier](https://azure.microsoft.com/pricing/details/cosmos-db/). | |
| 158 | +
|
| 159 | + > [!NOTE] |
| 160 | + > You can have up to one free tier Azure Cosmos DB account per Azure subscription and must opt-in when creating the account. If you do not see the option to apply the free tier discount, this means another account in the subscription has already been enabled with free tier. |
| 161 | +
|
| 162 | + :::image type="content" source="../media/create-account-portal/new-cosmos-account-page.png" lightbox="../media/create-account-portal/new-cosmos-account-page.png" alt-text="Screenshot of new account page for Azure Cosmos DB SQL API."::: |
| 163 | +
|
| 164 | +1. Select **Review + create**. |
| 165 | +
|
| 166 | +1. Review the settings you provide, and then select **Create**. It takes a few minutes to create the account. Wait for the portal page to display **Your deployment is complete** before moving on. |
| 167 | +
|
| 168 | +1. Select **Go to resource** to go to the Azure Cosmos DB account page. |
| 169 | +
|
| 170 | + :::image type="content" source="../media/create-account-portal/cosmos-deployment-complete.png" lightbox="../media/create-account-portal/cosmos-deployment-complete.png" alt-text="Screenshot of deployment page for Azure Cosmos DB SQL API resource."::: |
| 171 | +
|
| 172 | +1. From the Azure Cosmos DB SQL API account page, select the **Keys** navigation menu option. |
| 173 | +
|
| 174 | + :::image type="content" source="../media/get-credentials-portal/cosmos-keys-option.png" lightbox="../media/get-credentials-portal/cosmos-keys-option.png" alt-text="Screenshot of an Azure Cosmos DB SQL API account page. The Keys option is highlighted in the navigation menu."::: |
| 175 | +
|
| 176 | +1. Record the values from the **URI** and **PRIMARY KEY** fields. You'll use these values in a later step. |
| 177 | +
|
| 178 | + :::image type="content" source="../media/get-credentials-portal/cosmos-endpoint-key-credentials.png" lightbox="../media/get-credentials-portal/cosmos-endpoint-key-credentials.png" alt-text="Screenshot of Keys page with various credentials for an Azure Cosmos DB SQL API account."::: |
| 179 | +
|
| 180 | +#### [Resource Manager template](#tab/azure-resource-manager) |
| 181 | +
|
| 182 | +> [!NOTE] |
| 183 | +> Azure Resource Manager templates are written in two syntaxes, JSON and Bicep. This sample uses the [Bicep](../../../azure-resource-manager/bicep/overview.md) syntax. To learn more about the two syntaxes, see [comparing JSON and Bicep for templates](../../../azure-resource-manager/bicep/compare-template-syntax.md). |
| 184 | +
|
| 185 | +1. Create shell variables for *accountName*, *resourceGroupName*, and *location*. |
| 186 | +
|
| 187 | + ```azurecli-interactive |
| 188 | + # Variable for resource group name |
| 189 | + resourceGroupName="msdocs-cosmos" |
| 190 | +
|
| 191 | + # Variable for location |
| 192 | + location="westus" |
| 193 | +
|
| 194 | + # Variable for account name with a randomly generated suffix |
| 195 | + let suffix=$RANDOM*$RANDOM |
| 196 | + accountName="msdocs-$suffix" |
| 197 | + ``` |
| 198 | +
|
| 199 | +1. If you haven't already, sign in to the Azure CLI using the [``az login``](/cli/azure/reference-index#az-login) command. |
| 200 | +
|
| 201 | +1. Use the [``az group create``](/cli/azure/group#az-group-create) command to create a new resource group in your subscription. |
| 202 | +
|
| 203 | + ```azurecli-interactive |
| 204 | + az group create \ |
| 205 | + --name $resourceGroupName \ |
| 206 | + --location $location |
| 207 | + ``` |
| 208 | +
|
| 209 | +1. Create a new ``.bicep`` file with the deployment template in the Bicep syntax. |
| 210 | +
|
| 211 | + :::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.documentdb/cosmosdb-sql-minimal/main.bicep"::: |
| 212 | +
|
| 213 | +1. Deploy the Azure Resource Manager (ARM) template with [``az deployment group create``](/cli/azure/deployment/group#az-deployment-group-create) |
| 214 | +specifying the filename using the **template-file** parameter and the name ``initial-bicep-deploy`` using the **name** parameter. |
| 215 | +
|
| 216 | + ```azurecli-interactive |
| 217 | + az deployment group create \ |
| 218 | + --resource-group $resourceGroupName \ |
| 219 | + --name initial-bicep-deploy \ |
| 220 | + --template-file main.bicep \ |
| 221 | + --parameters accountName=$accountName |
| 222 | + ``` |
| 223 | +
|
| 224 | + > [!NOTE] |
| 225 | + > In this example, we assume that the name of the Bicep file is **main.bicep**. |
| 226 | +
|
| 227 | +1. Validate the deployment by showing metadata from the newly created account using [``az cosmosdb show``](/cli/azure/cosmosdb#az-cosmosdb-show). |
| 228 | +
|
| 229 | + ```azurecli-interactive |
| 230 | + az cosmosdb show \ |
| 231 | + --resource-group $resourceGroupName \ |
| 232 | + --name $accountName |
| 233 | + ``` |
| 234 | +
|
| 235 | +--- |
0 commit comments