Muokkaa

Jaa


Use Azure CLI to create a API for Gremlin account, database, and graph with autoscale

APPLIES TO: Gremlin

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

Prerequisites

  • If you don't have an Azure subscription, create an Azure free account before you begin.

  • This script requires Azure CLI version 2.30 or later.

    • You can run the script in the Bash environment in Azure Cloud Shell. When Cloud Shell opens, make sure to select Bash in the environment field at the upper left of the shell window. Cloud Shell has the latest version of Azure CLI.

    • If you prefer, you can install Azure CLI to run the script locally. Run az version to find your Azure CLI version, and run az upgrade if you need to upgrade. Sign in to Azure by running az login.

Sample script

This script uses the following commands:

# Create a Gremlin API database and graph with autoscale

# Variable block
let "randomIdentifier=$RANDOM*$RANDOM"
location="East US"
resourceGroup="msdocs-cosmosdb-rg-$randomIdentifier"
tag="autoscale-gremlin-cosmosdb"
account="msdocs-account-cosmos-$randomIdentifier" #needs to be lower case
database="msdocs-db-gremlin-cosmos"
graph="msdocs-graph1-gremlin-cosmos"
partitionKey="/partitionKey"
maxThroughput=1000 #minimum = 1000

# 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 --default-consistency-level Eventual --locations regionName="$location" 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 with autoscale
echo "Creating $graph"
az cosmosdb gremlin graph create --account-name $account --resource-group $resourceGroup --database-name $database --name $graph --partition-key-path $partitionKey --max-throughput $maxThroughput

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