Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
29 lines (20 sloc) 1.45 KB

Create CosmosDB Database and Corresponding User

Script creates a database in CosmosDB container and a corresponding user. As output, it prints a temporary token for the user.

Notice: cosmosdb does not support users as you would expect in a database. You have to use your service keys (az cosmosdb get-keys --resource-group RESOURCE_GROUP --name COSMOSDB_CONTAINER) or temporary user/token. The temporary user/token will not work if you want to use the mongodb client.

# az cosmosdb show --resource-group RESOURCE_GROUP --name COSMOSDB_NAME --query 'documentEndpoint' -o tsv
export COSMOSDB_ENDPOINT=
# az cosmosdb list-keys --resource-group RESOURCE_GROUP --name COSMOSDB_NAME --query 'primaryMasterKey' -o tsv
export COSMOSDB_MASTERKEY=
export USER_NAME=
export DB_NAME=

python create_db_and_creds.py

If you want to automatize CosmosDB, the best source are the tests for CosmosDB python client. You will find the links below.

Reference