Use Azure CLI to create a Gremlin serverless account, database, and graph

APPLIES TO: Gremlin

The script in this article creates an Azure Cosmos DB for Gremlin serverless account, database, and graph.

Prerequisites

  • If you don't have an Azure trail subscription, create a trial subscription before you begin.

  • This script requires Azure CLI version 2.30 or later.

    Note

    Before you can use Azure CLI in Microsoft Azure operated by 21Vianet, please run az cloud set -n AzureChinaCloud first to change the cloud environment. If you want to switch back to Azure Public Cloud, run az cloud set -n AzureCloud again.

Sample script

This script uses the following commands:

# Create a Gremlin serverless account, database and graph

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="chinaeast2"
failoverLocation="chinanorth2"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="serverless-gremlin-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
database="msdocs-db-gremlin-cosmos"
graph="msdocs-graph1-gremlin-cosmos"
partitionKey="/partitionKey"

# Create a resource group
echo "Creating $resourceGroup in $location..."
az group create --name $resourceGroup --location "$location" --tags $tag

# Create a Cosmos account for Gremlin API
echo "Creating $account"
az cosmosdb create --name $account --resource-group $resourceGroup --capabilities EnableGremlin EnableServerless --default-consistency-level Eventual --locations regionName="$failoverLocation" failoverPriority=0 isZoneRedundant=False

# Create a Gremlin database
echo "Creating $database with $account"
az cosmosdb gremlin database create --account-name $account --resource-group $resourceGroup --name $database

# Create a Gremlin graph
echo "Creating $graph"
az cosmosdb gremlin graph create --account-name $account --resource-group $resourceGroup --database-name $database --name $graph --partition-key-path $partitionKey
# </FullScript>

# echo "Deleting all resources"
# az group delete --name $resourceGroup -y

Delete resources

If you don't need the resources the script created, use the az group delete command to delete the resource group and all resources it contains, including the Azure Cosmos DB account and database.

az group delete --name $resourceGroup

Next steps

Azure Cosmos DB CLI documentation