Use Azure CLI to create an Azure Cosmos DB for Table serverless account and table
APPLIES TO: Table
The script in this article creates an Azure Cosmos DB for Table serverless account and table.
This script requires Azure CLI version 2.12.1 or later.
You can run the script in the Bash environment in Azure Cloud Shell. When Cloud Shell opens, make sure Bash appears in the environment field at the upper left of the shell window. Cloud Shell always has the latest version of Azure CLI.
Cloud Shell is automatically authenticated under the account you used to sign in to the Azure portal. You can use az account set to sign in with a different subscription, replacing
<subscriptionId>with your Azure subscription ID.
subscription="<subscriptionId>" # add subscription here az account set -s $subscription # ...or use 'az login'
If you prefer, you can install Azure CLI to run the script locally. Run az version to find the Azure CLI version and dependent libraries that are installed, and run az upgrade if you need to upgrade. If prompted, install Azure CLI extensions. If you're running Windows or macOS, consider running Azure CLI in a Docker container.
Run the following script to create an Azure resource group, an Azure Cosmos DB for Table serverless account, and API for Table table. The resources might take a while to create.
# Create a Table API serverless account and table # Variable block let "randomIdentifier=$RANDOM*$RANDOM" location="East US" resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier" tag="serverless-table-cosmosdb" account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case table="msdocs-table-cosmos-$randomIdentifier" # Create a resource group echo "Creating $resourceGroup in $location..." az group create --name $resourceGroup --location "$location" --tags $tag # Create a Cosmos account for Table API echo "Creating $account" az cosmosdb create --name $account --resource-group $resourceGroup --capabilities EnableTable EnableServerless --default-consistency-level Eventual --locations regionName="$location" failoverPriority=0 isZoneRedundant=False \ # Create a Table API Table az cosmosdb table create --account-name $account --resource-group $resourceGroup --name $table
This script uses the following commands:
- az group create creates a resource group to store all resources.
- az cosmosdb create with
--capabilities EnableTable EnableServerlesscreates an Azure Cosmos DB serverless account for API for Table.
- az cosmosdb table create creates an Azure Cosmos DB for Table table.
Clean up resources
If you no longer need the resources you created, use the az group delete command to delete the resource group and all resources it contains. These resources include the Azure Cosmos DB account and table. The resources might take a while to delete.
az group delete --name $resourceGroup
Submit and view feedback for