diff --git a/cosmosdb/cassandra/create.sh b/cosmosdb/cassandra/create.sh new file mode 100644 index 00000000..df6c4476 --- /dev/null +++ b/cosmosdb/cassandra/create.sh @@ -0,0 +1,63 @@ +!/bin/bash + +# Create a Cassandra keyspace and table + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Variables for Cassandra API resources +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case +keySpaceName='keyspace1' +tableName='table1' + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a Cosmos account for Cassandra API +az cosmosdb create \ + -n $accountName \ + -g $resourceGroupName \ + --capabilities EnableCassandra \ + --default-consistency-level Eventual \ + --locations regionName='West US 2' failoverPriority=0 isZoneRedundant=False \ + --locations regionName='East US 2' failoverPriority=1 isZoneRedundant=False + +# Create a Cassandra Keyspace +az cosmosdb cassandra keyspace create \ + -a $accountName \ + -g $resourceGroupName \ + -n $keySpaceName + +# Define the schema for the table +schema=$(cat << EOF +{ + "columns": [ + {"name": "columnA","type": "uuid"}, + {"name": "columnB","type": "int"}, + {"name": "columnC","type": "text"} + ], + "partitionKeys": [ + {"name": "columnA"} + ], + "clusterKeys": [ + { "name": "columnB", "orderBy": "asc" } + ] +} +EOF +) +# Persist schema to json file +echo "$schema" > "schema-$uniqueId.json" + +# Create the Cassandra table +az cosmosdb cassandra table create \ + -a $accountName \ + -g $resourceGroupName \ + -k $keySpaceName \ + -n $tableName \ + --throughput 400 \ + --schema @schema-$uniqueId.json + +# Clean up temporary schema file +rm -f "schema-$uniqueId.json" diff --git a/cosmosdb/cassandra/throughput.sh b/cosmosdb/cassandra/throughput.sh new file mode 100644 index 00000000..c1c981b2 --- /dev/null +++ b/cosmosdb/cassandra/throughput.sh @@ -0,0 +1,72 @@ +!/bin/bash + +# Update throughput for Cassandra keyspace and table + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Variables for Cassandra API resources +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case +keySpaceName='keyspace1' +tableName='table1' + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a new Cosmos account for Cassandra API +az cosmosdb create \ + -n $accountName \ + -g $resourceGroupName \ + --capabilities EnableCassandra + +# Create a new Cassandra Keyspace with shared throughput +az cosmosdb cassandra keyspace create \ + -a $accountName \ + -g $resourceGroupName \ + -n $keySpaceName \ + --throughput 400 + +# Define the schema for the Table +schema=$(cat << EOF +{ + "columns": [ + {"name": "columnA","type": "uuid"}, + {"name": "columnB","type": "text"} + ], + "partitionKeys": [{"name": "columnA"}] +} +EOF +) +# Persist schema to json file +echo "$schema" > "schema-$uniqueId.json" + +# Create a Cassandra table with dedicated throughput +az cosmosdb cassandra table create \ + -a $accountName \ + -g $resourceGroupName \ + -k $keySpaceName \ + -n $tableName \ + --throughput 400 \ + --schema @schema-$uniqueId.json + +# Delete schema file +rm -f "schema-$uniqueId.json" + +read -p 'Press any key to increase Keyspace throughput to 500' + +az cosmosdb cassandra keyspace throughput update \ + -a $accountName \ + -g $resourceGroupName \ + -n $keySpaceName \ + --throughput 500 + +read -p 'Press any key to increase Table throughput to 500' + +az cosmosdb cassandra table throughput update \ + -a $accountName \ + -g $resourceGroupName \ + -k $keySpaceName \ + -n $tableName \ + --throughput 500 diff --git a/cosmosdb/common/ipfirewall.sh b/cosmosdb/common/ipfirewall.sh new file mode 100644 index 00000000..bf35a6d4 --- /dev/null +++ b/cosmosdb/common/ipfirewall.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +# Create an Azure Cosmos Account with IP Firewall + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Resource group and Cosmos account variables +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a Cosmos DB account with default values and IP Firewall enabled +# Use appropriate values for --kind or --capabilities for other APIs +az cosmosdb create \ + -n $accountName \ + -g $resourceGroupName \ + --ip-range-filter '192.168.221.17' diff --git a/cosmosdb/common/keys.sh b/cosmosdb/common/keys.sh new file mode 100644 index 00000000..4b446a64 --- /dev/null +++ b/cosmosdb/common/keys.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +# This sample shows the following: +# List all account keys +# List read only account keys +# List connection strings +# Regenerate account keys + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Resource group and Cosmos account variables +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a Cosmos DB account with default values +# Use appropriate values for --kind or --capabilities for other APIs +az cosmosdb create -n $accountName -g $resourceGroupName + +read -p "Press any key to list account keys" +# List all account keys +az cosmosdb keys list \ + -n $accountName \ + -g $resourceGroupName + +read -p "Press any key to list read only account keys" +# List read-only keys +az cosmosdb list-read-only-keys \ + -n $accountName \ + -g $resourceGroupName + +read -p "Press any key to list connection strings" +# List connection strings +az cosmosdb list-connection-strings \ + -n $accountName \ + -g $resourceGroupName + +read -p "Press any key to regenerate secondary account keys" +# Regenerate secondary account keys +# key-kind values: primary, primaryReadonly, secondary, secondaryReadonly +az cosmosdb regenerate-key \ + -n $accountName \ + -g $resourceGroupName \ + --key-kind secondary diff --git a/cosmosdb/common/regions.sh b/cosmosdb/common/regions.sh new file mode 100644 index 00000000..25c1321f --- /dev/null +++ b/cosmosdb/common/regions.sh @@ -0,0 +1,46 @@ +!/bin/bash + +# This sample shows the following: +# Add regions to an existing Cosmos account +# Change regional failover priority (applies to accounts using automatic failover) +# Trigger a manual failover from primary to secondary region (applies to accounts with manual failover) + +# Note: Azure Comos accounts cannot include updates to regions with changes to other properties in the same operation + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Resource group and Cosmos account variables +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a Cosmos DB account with default values +# Use appropriate values for --kind or --capabilities for other APIs +az cosmosdb create -n $accountName -g $resourceGroupName + +read -p "Press any key to add additional regions to this account" +az cosmosdb update \ + -n $accountName \ + -g $resourceGroupName \ + --locations regionName='West US 2' failoverPriority=0 isZoneRedundant=False \ + --locations regionName='East US 2' failoverPriority=1 isZoneRedundant=False \ + --locations regionName='South Central US' failoverPriority=2 isZoneRedundant=False + +read -p "Press any key to change the failover priority" +# Make South Central US the next region to fail over to instea of East US 2 +az cosmosdb failover-priority-change \ + -n $accountName \ + -g $resourceGroupName \ + --failover-policies 'West US 2'=0 'South Central US'=1 'East US 2'=2 + + +read -p "Press any key to trigger a manual failover by changing region 0" +# Initiate a manual failover and promote East US 2 as primary write region +az cosmosdb failover-priority-change \ + -n $accountName \ + -g $resourceGroupName \ + --failover-policies 'East US 2'=0 'West US 2'=1 'South Central US'=2 diff --git a/cosmosdb/common/service-endpoints-ignore-missing-vnet.sh b/cosmosdb/common/service-endpoints-ignore-missing-vnet.sh new file mode 100644 index 00000000..ed7b8569 --- /dev/null +++ b/cosmosdb/common/service-endpoints-ignore-missing-vnet.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +# Create an Azure Cosmos Account with a service endpoint connected to a backend subnet +# that is not yet enabled for service endpoints. + +# This sample demonstrates how to configure service endpoints for existing Cosmos account where +# the connected subnet is not yet configured for service endpoints. +# This sample will then configure the subnet for service endpoints. + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Resource group and Cosmos account variables +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case + +# Variables for a new Virtual Network with two subnets +vnetName='myVnet' +frontEnd='FrontEnd' +backEnd='BackEnd' + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a virtual network with a front-end subnet +az network vnet create \ + -n $vnetName \ + -g $resourceGroupName \ + --address-prefix 10.0.0.0/16 \ + --subnet-name $frontEnd \ + --subnet-prefix 10.0.1.0/24 + +# Create a back-end subnet but without specifying --service-endpoints Microsoft.AzureCosmosDB +az network vnet subnet create \ + -n $backEnd \ + -g $resourceGroupName \ + --address-prefix 10.0.2.0/24 \ + --vnet-name $vnetName + +svcEndpoint=$(az network vnet subnet show -g $resourceGroupName -n $backEnd --vnet-name $vnetName --query 'id' -o tsv) + +# Create a Cosmos DB account with default values +# Use appropriate values for --kind or --capabilities for other APIs +az cosmosdb create -n $accountName -g $resourceGroupName + +# Add the virtual network rule but ignore the missing service endpoint on the subnet +az cosmosdb networ-rule add \ + -n $accountName \ + -g $resourceGroupName \ + --virtual-network $vnetName \ + --subnet svcEndpoint \ + --ignore-missing-vnet-service-endpoint true + +read -p'Press any key to configure the subnet for service endpoints' + +az network vnet subnet update \ + -n $backEnd \ + -g $resourceGroupName \ + --vnet-name $vnetName \ + --service-endpoints Microsoft.AzureCosmosDB diff --git a/cosmosdb/common/service-endpoints.sh b/cosmosdb/common/service-endpoints.sh new file mode 100644 index 00000000..18217788 --- /dev/null +++ b/cosmosdb/common/service-endpoints.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Create an Azure Cosmos Account with a service endpoint connected to a backend subnet + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Resource group and Cosmos account variables +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case + +# Variables for a new Virtual Network with two subnets +vnetName='myVnet' +frontEnd='FrontEnd' +backEnd='BackEnd' + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a virtual network with a front-end subnet +az network vnet create \ + -n $vnetName \ + -g $resourceGroupName \ + --address-prefix 10.0.0.0/16 \ + --subnet-name $frontEnd \ + --subnet-prefix 10.0.1.0/24 + +# Create a back-end subnet +az network vnet subnet create \ + -n $backEnd \ + -g $resourceGroupName \ + --address-prefix 10.0.2.0/24 \ + --vnet-name $vnetName \ + --service-endpoints Microsoft.AzureCosmosDB + +svcEndpoint=$(az network vnet subnet show -g $resourceGroupName -n $backEnd --vnet-name $vnetName --query 'id' -o tsv) + +# Create a Cosmos DB account with default values and service endpoints +# Use appropriate values for --kind or --capabilities for other APIs +az cosmosdb create \ + -n $accountName \ + -g $resourceGroupName \ + --enable-virtual-network true \ + --virtual-network-rules $svcEndpoint diff --git a/cosmosdb/gremlin/create.sh b/cosmosdb/gremlin/create.sh new file mode 100644 index 00000000..9c5fa8b8 --- /dev/null +++ b/cosmosdb/gremlin/create.sh @@ -0,0 +1,69 @@ +!/bin/bash + +# Create a Gremlin database and graph + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Variables for Gremlin API resources +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case +databaseName='database1' +graphName='graph1' + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a Cosmos account for Gremlin API +az cosmosdb create \ + -n $accountName \ + -g $resourceGroupName \ + --capabilities EnableGremlin \ + --default-consistency-level Eventual \ + --locations regionName='West US 2' failoverPriority=0 isZoneRedundant=False \ + --locations regionName='East US 2' failoverPriority=1 isZoneRedundant=False + +# Create a Gremlin database +az cosmosdb gremlin database create \ + -a $accountName \ + -g $resourceGroupName \ + -n $databaseName + +# Define the index policy for the graph, include spatial and composite indexes +idxpolicy=$(cat << EOF +{ + "indexingMode": "consistent", + "includedPaths": [ + {"path": "/*"} + ], + "excludedPaths": [ + { "path": "/headquarters/employees/?"} + ], + "spatialIndexes": [ + {"path": "/*", "types": ["Point"]} + ], + "compositeIndexes":[ + [ + { "path":"/name", "order":"ascending" }, + { "path":"/age", "order":"descending" } + ] + ] +} +EOF +) +# Persist index policy to json file +echo "$idxpolicy" > "idxpolicy-$uniqueId.json" + +# Create a Gremlin graph +az cosmosdb gremlin graph create \ + -a $accountName \ + -g $resourceGroupName \ + -d $databaseName \ + -n $graphName \ + -p '/zipcode' \ + --throughput 400 \ + --idx @idxpolicy-$uniqueId.json + +# Clean up temporary index policy file +rm -f "idxpolicy-$uniqueId.json" diff --git a/cosmosdb/gremlin/throughput.sh b/cosmosdb/gremlin/throughput.sh new file mode 100644 index 00000000..5acf5bfb --- /dev/null +++ b/cosmosdb/gremlin/throughput.sh @@ -0,0 +1,55 @@ +!/bin/bash + +# Update the throughput for a Gremlin database and graph + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Variables for Gremlin API resources +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case +databaseName='database1' +graphName='graph1' + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a Cosmos account for Gremlin API +az cosmosdb create \ + -n $accountName \ + -g $resourceGroupName \ + --capabilities EnableGremlin + +# Create a Gremlin database with shared throughput +az cosmosdb gremlin database create \ + -a $accountName \ + -g $resourceGroupName \ + -n $databaseName \ + --throughput 400 + +# Create a Gremlin graph with dedicated throughput +az cosmosdb gremlin graph create \ + -a $accountName \ + -g $resourceGroupName \ + -d $databaseName \ + -n $graphName \ + -p '/zipcode' \ + --throughput 400 + +read -p 'Press any key to increase Database throughput to 500' + +az cosmosdb gremlin database throughput update \ + -a $accountName \ + -g $resourceGroupName \ + -n $databaseName \ + --throughput 500 + +read -p 'Press any key to increase Graph throughput to 500' + +az cosmosdb gremlin graph throughput update \ + -a $accountName \ + -g $resourceGroupName \ + -d $databaseName \ + -n $graphName \ + --throughput 500 diff --git a/cosmosdb/mongodb/create.sh b/cosmosdb/mongodb/create.sh new file mode 100644 index 00000000..a4dc7937 --- /dev/null +++ b/cosmosdb/mongodb/create.sh @@ -0,0 +1,61 @@ +!/bin/bash + +# Create a MongoDB API database and collection + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Variables for MongoDB API resources +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case +databaseName='database1' +collectionName='collection1' + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a Cosmos account for MongoDB API +az cosmosdb create \ + -n $accountName \ + -g $resourceGroupName \ + --kind MongoDB \ + --default-consistency-level Eventual \ + --locations regionName='West US 2' failoverPriority=0 isZoneRedundant=False \ + --locations regionName='East US 2' failoverPriority=1 isZoneRedundant=False + +# Create a MongoDB API database +az cosmosdb mongodb database create \ + -a $accountName \ + -g $resourceGroupName \ + -n $databaseName + +# Define the index policy for the collection, include unique index and 30-day TTL +idxpolicy=$(cat << EOF +[ + { + "key": {"keys": ["user_id", "user_address"]}, + "options": {"unique": "true"} + }, + { + "key": {"keys": ["_ts"]}, + "options": {"expireAfterSeconds": 2629746} + } +] +EOF +) +# Persist index policy to json file +echo "$idxpolicy" > "idxpolicy-$uniqueId.json" + +# Create a MongoDB API collection +az cosmosdb mongodb collection create \ + -a $accountName \ + -g $resourceGroupName \ + -d $databaseName \ + -n $collectionName \ + --shard 'user_id' \ + --throughput 400 \ + --idx @idxpolicy-$uniqueId.json + +# Clean up temporary index policy file +rm -f "idxpolicy-$uniqueId.json" diff --git a/cosmosdb/mongodb/throughput.sh b/cosmosdb/mongodb/throughput.sh new file mode 100644 index 00000000..b40d7fb9 --- /dev/null +++ b/cosmosdb/mongodb/throughput.sh @@ -0,0 +1,69 @@ +!/bin/bash + +# Update throughput for MongoDB API database and collection + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Variables for MongoDB API resources +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case +databaseName='database1' +collectionName='collection1' + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a Cosmos account for MongoDB API +az cosmosdb create \ + -n $accountName \ + -g $resourceGroupName \ + --kind MongoDB + +# Create a MongoDB API database with shared throughput +az cosmosdb mongodb database create \ + -a $accountName \ + -g $resourceGroupName \ + -n $databaseName \ + --throughput 400 + +# Define a minimal index policy for the collection +idxpolicy=$(cat << EOF +[ + {"key": {"keys": ["user_id"]}} +] +EOF +) +# Persist index policy to json file +echo "$idxpolicy" > "idxpolicy-$uniqueId.json" + +# Create a MongoDB API collection +az cosmosdb mongodb collection create \ + -a $accountName \ + -g $resourceGroupName \ + -d $databaseName \ + -n $collectionName \ + --shard 'user_id' \ + --throughput 400 \ + --idx @idxpolicy-$uniqueId.json + +# Clean up temporary index policy file +rm -f "idxpolicy-$uniqueId.json" + +read -p 'Press any key to increase Database throughput to 500' + +az cosmosdb mongodb database throughput update \ + -a $accountName \ + -g $resourceGroupName \ + -n $databaseName \ + --throughput 500 + +read -p 'Press any key to increase Collection throughput to 500' + +az cosmosdb mongodb collection throughput update \ + -a $accountName \ + -g $resourceGroupName \ + -d $databaseName \ + -n $collectionName \ + --throughput 500 diff --git a/cosmosdb/sql/create.sh b/cosmosdb/sql/create.sh new file mode 100644 index 00000000..276a14fc --- /dev/null +++ b/cosmosdb/sql/create.sh @@ -0,0 +1,68 @@ +!/bin/bash + +# Create a SQL API database and container + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Variables for SQL API resources +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case +databaseName='database1' +containerName='container1' + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a Cosmos account for SQL API +az cosmosdb create \ + -n $accountName \ + -g $resourceGroupName \ + --default-consistency-level Eventual \ + --locations regionName='West US 2' failoverPriority=0 isZoneRedundant=False \ + --locations regionName='East US 2' failoverPriority=1 isZoneRedundant=False + +# Create a SQL API database +az cosmosdb sql database create \ + -a $accountName \ + -g $resourceGroupName \ + -n $databaseName + +# Define the index policy for the container, include spatial and composite indexes +idxpolicy=$(cat << EOF +{ + "indexingMode": "consistent", + "includedPaths": [ + {"path": "/*"} + ], + "excludedPaths": [ + { "path": "/headquarters/employees/?"} + ], + "spatialIndexes": [ + {"path": "/*", "types": ["Point"]} + ], + "compositeIndexes":[ + [ + { "path":"/name", "order":"ascending" }, + { "path":"/age", "order":"descending" } + ] + ] +} +EOF +) +# Persist index policy to json file +echo "$idxpolicy" > "idxpolicy-$uniqueId.json" + +# Create a SQL API container +az cosmosdb sql container create \ + -a $accountName \ + -g $resourceGroupName \ + -d $databaseName \ + -n $containerName \ + -p '/zipcode' \ + --throughput 400 \ + --idx @idxpolicy-$uniqueId.json + +# Clean up temporary index policy file +rm -f "idxpolicy-$uniqueId.json" diff --git a/cosmosdb/sql/throughput.sh b/cosmosdb/sql/throughput.sh new file mode 100644 index 00000000..12c30dce --- /dev/null +++ b/cosmosdb/sql/throughput.sh @@ -0,0 +1,54 @@ +!/bin/bash + +# Update throughput for a SQL API database and container + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Variables for SQL API resources +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case +databaseName='database1' +containerName='container1' + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a Cosmos account for SQL API +az cosmosdb create \ + -n $accountName \ + -g $resourceGroupName + +# Create a SQL API database with shared throughput +az cosmosdb sql database create \ + -a $accountName \ + -g $resourceGroupName \ + -n $databaseName \ + --throughput 400 + +# Create a SQL API container, default index policy, dedicated throughput +az cosmosdb sql container create \ + -a $accountName \ + -g $resourceGroupName \ + -d $databaseName \ + -n $containerName \ + -p '/id' \ + --throughput 400 + +read -p 'Press any key to increase Database throughput to 500' + +az cosmosdb sql database throughput update \ + -a $accountName \ + -g $resourceGroupName \ + -n $databaseName \ + --throughput 400 + +read -p 'Press any key to increase Container throughput to 500' + +az cosmosdb sql container throughput update \ + -a $accountName \ + -g $resourceGroupName \ + -d $databaseName \ + -n $containerName \ + --throughput 500 diff --git a/cosmosdb/table/create.sh b/cosmosdb/table/create.sh new file mode 100644 index 00000000..4db49859 --- /dev/null +++ b/cosmosdb/table/create.sh @@ -0,0 +1,31 @@ +!/bin/bash + +# Create a Table API table + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Variables for Cassandra API resources +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case +tableName='table1' + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a Cosmos account for Table API +az cosmosdb create \ + -n $accountName \ + -g $resourceGroupName \ + --capabilities EnableTable \ + --default-consistency-level Eventual \ + --locations regionName='West US 2' failoverPriority=0 isZoneRedundant=False \ + --locations regionName='East US 2' failoverPriority=1 isZoneRedundant=False + +# Create a Table API Table +az cosmosdb table create \ + -a $accountName \ + -g $resourceGroupName \ + -n $tableName \ + --throughput 400 diff --git a/cosmosdb/table/throughput.sh b/cosmosdb/table/throughput.sh new file mode 100644 index 00000000..bfd7e1f9 --- /dev/null +++ b/cosmosdb/table/throughput.sh @@ -0,0 +1,36 @@ +!/bin/bash + +# Update throughput for Table API table + +# Generate a unique 10 character alphanumeric string to ensure unique resource names +uniqueId=$(env LC_CTYPE=C tr -dc 'a-z0-9' < /dev/urandom | fold -w 10 | head -n 1) + +# Variables for Cassandra API resources +resourceGroupName="Group-$uniqueId" +location='westus2' +accountName="cosmos-$uniqueId" #needs to be lower case +tableName='table1' + +# Create a resource group +az group create -n $resourceGroupName -l $location + +# Create a Cosmos account for Table API +az cosmosdb create \ + -n $accountName \ + -g $resourceGroupName \ + --capabilities EnableTable \ + +# Create a Table API Table +az cosmosdb table create \ + -a $accountName \ + -g $resourceGroupName \ + -n $tableName \ + --throughput 400 + +read -p 'Press any key to increase Table throughput to 500' + +az cosmosdb table throughput update \ + -a $accountName \ + -g $resourceGroupName \ + -n $tableName \ + --throughput 500