Juvis
Juvis

Reputation: 41

Is it possible to provision throughput on Database level through code or arm template using Table API in cosmos db?

I am trying to set up an release pipeline in Azure DevOps that deploy an Azure environment using Azure Resource Manager Templates. One of the resources I want to create is a Cosmos DB instance using the Azure Table Api and I want to provision "Account level throughput" for the whole database and not pr. table. I am able to create the Cosmos DB instance with the correct api through the ARM template, but I'm not able to set "Account level throughput" to "On" through the template or by using the Microsoft.Azure.Cosmos.Table api.

The only way I'm able to configure this is by logging into the Azure portal and do it manually. Is it possible to automate this through the ARM template or by using Powershell or the Microsoft.Azure.Cosmos.Table api?

This is the template I use at the moment

{
      "type": "Microsoft.DocumentDB/databaseAccounts",
      "name": "[variables('cosmosStreamDBName')]",
      "apiVersion": "2016-03-31",
      "location": "[parameters('location')]",
      "tags": {
        "defaultExperience": "Azure Table"
      },
      "kind": "GlobalDocumentDB",
      "properties": {
        "capabilities": [ { "name": "EnableTable" } ],
        "consistencyPolicy": {
          "defaultConsistencyLevel": "BoundedStaleness",
          "maxIntervalInSeconds": 86400,
          "maxStalenessPrefix": 1000000
        },
        "databaseAccountOfferType": "Standard",
        "enableAutomaticFailover": false,
        "enableMultipleWriteLocations": false,
        "isVirtualNetworkFilterEnabled": false,
        "virtualNetworkRules": [],
        "locations": [
          {
            "locationName": "[parameters('location')]",
            "failoverPriority": 0
          }
        ]
      }
    }

This is an example on how I provision the throughput on database level when using the SQL api:

var client = new DocumentClient(
   new Uri(EndpointUri), 
   PrimaryKey, 
   serializerSettings: Settings
);

var db =  await client.CreateDatabaseIfNotExistsAsync(
   new Database { Id = DatabaseName }, 
   new RequestOptions() { 
     PartitionKey = new PartitionKey(key), 
     OfferThroughput = 400 
   }
);

Upvotes: 3

Views: 1013

Answers (4)

Leonid Krupnov
Leonid Krupnov

Reputation: 11

That's now possible: see https://github.com/Azure/azure-quickstart-templates/blob/master/101-cosmosdb-sql/azuredeploy.json

    {
        "type": "Microsoft.DocumentDB/databaseAccounts/sqlDatabases",
        "name": "[concat(variables('accountName'), '/', parameters('databaseName'))]",
        "apiVersion": "2019-08-01",
        "dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts', variables('accountName'))]" ],
        "properties":{
            "resource":{
                "id": "[parameters('databaseName')]"
            },
            "options": { "throughput": "[parameters('sharedThroughput')]" }
        }
    },

Upvotes: 1

Juvis
Juvis

Reputation: 41

I asked the Cosmos DB team on Twitter and got this answer:

"As of today this is only available through the portal. Please feel free to add this as a suggestion on our User Voice so we can look at this in our next planning cycle, https://feedback.azure.com/forums/263030-azure-cosmos-db?category_id=321997"

https://twitter.com/AzureCosmosDB/status/1175071433229312001

Hopefully they will make this possible at a later stage.

I've created a suggestion for the Cosmos DB team that you can vote for: https://feedback.azure.com/forums/263030-azure-cosmos-db/suggestions/38682238-set-account-level-throughput-on-cosmos-db-table-ap

Upvotes: 1

Mark Brown
Mark Brown

Reputation: 8763

Please refer to the ARM templates below to provision a Cosmos table with throughput and update that throughput later.

This arm template creates a Cosmos Table with initial throughput set. https://azure.microsoft.com/en-us/resources/templates/101-cosmosdb-table/

This template updates the throughput for an existing table. https://azure.microsoft.com/en-us/resources/templates/101-cosmosdb-table-ru-update/

We are currently working on allowing customers to redeploy the same template used to provision the account and table resource to update throughput as well. This should be available in October or early November.

Thanks.

Upvotes: 0

4c74356b41
4c74356b41

Reputation: 72171

try the following arm template piece:

{
    "type": "Microsoft.DocumentDB/databaseAccounts/apis/tables",
    "name": "[concat(account-name, '/table/', database-name)]",
    "apiVersion": "2016-03-31",
    "dependsOn": [ "[resourceId('Microsoft.DocumentDB/databaseAccounts/', account-name)]" ],
    "properties":{
        "resource":{
            "id": "table-name"
        },
        "options": {
            "x-ms-offer-throughput": 1000
        }
    }
}

Reference:
https://learn.microsoft.com/en-us/rest/api/cosmos-db/create-a-collection
https://learn.microsoft.com/en-us/rest/api/cosmos-db-resource-provider/databaseaccounts/createupdatetable

ps. not sure about x-ms-offer-throughput, it might be just throughput

Upvotes: 0

Related Questions