0

I am trying to scale the CosmosDB Container using Powershell but couldn't find anything in the docs. I tried the following script which didn't work.

$resourceName = $CosmosDB + "/sql/" + $CosmosDatabase + "/" + $CosmosContainer
   $ContainerProperties = @{
       "resource"=@{
           "id"=$CosmosContainer;
           "partitionKey"=@{
               "paths"=@("/DefaultKey");
               "kind"="Hash"
           }
       };
       "options"=@{ "Throughput"=$CosmosScale }
   }

   Set-AzResource -ResourceType "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers" -ApiVersion "2015-04-08" -ResourceGroupName $resourceGroup -Name $resourceName -PropertyObject $ContainerProperties -Force

Any insights are appreciated.

2 Answers 2

2

Here is a PS script that will update throughput on either a database or container for a SQL (Core) API account.

# Update RU for an Azure Cosmos DB SQL (Core) API database or container
$resourceGroupName = "myResourceGroup"
$accountName = "mycosmosaccount"
$databaseName = "database1"
$containerName = "container1"
$databaseResourceName = $accountName + "/sql/" + $databaseName + "/throughput"
$containerResourceName = $accountName + "/sql/" + $databaseName + "/" + $containerName + "/throughput"
$throughput = 500
$updateResource = "database" # or "container"

$properties = @{
    "resource"=@{"throughput"=$throughput}
}

if($updateResource -eq "database"){
Set-AzResource -ResourceType "Microsoft.DocumentDb/databaseAccounts/apis/databases/settings" `
    -ApiVersion "2015-04-08" -ResourceGroupName $resourceGroupName `
    -Name $databaseResourceName -PropertyObject $properties
}
elseif($updateResource -eq "container"){
Set-AzResource -ResourceType "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers/settings" `
    -ApiVersion "2015-04-08" -ResourceGroupName $resourceGroupName `
    -Name $containerResourceName -PropertyObject $properties
}
else {
    Write-Host("Must select database or container")
} 
Sign up to request clarification or add additional context in comments.

Comments

1

I have used this to update the Azure CosmosDb (SQL API) Collections on automation account but which gets timed Out with the cmdlet Set-AzResource - sometimes it works

Get-AzResource -ResourceType Microsoft.DocumentDB/databaseAccounts

$containerResourceType = "Microsoft.DocumentDb/databaseAccounts/apis/databases/containers/settings"

Using Set command with API Version in Runbook which got failed with ‘Operation failed because a request timed out.’

Set-AzResource -ResourceType $containerResourceType ***

Reference: https://serverfault.com/questions/967942/scaling-cosmosdb-container-using-powershell

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.