Kartik Shandilya
Kartik Shandilya

Reputation: 3924

Scaling CosmosDB Container using Powershell

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.

Upvotes: 0

Views: 401

Answers (2)

Venkatesh
Venkatesh

Reputation: 45

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

Upvotes: 1

Mark Brown
Mark Brown

Reputation: 8763

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")
} 

Upvotes: 2

Related Questions