Create an Azure Data Explorer cluster and database

Azure Data Explorer is a fast, fully managed data analytics service for real-time analysis on large volumes of data streaming from applications, websites, IoT devices, and more. To use Azure Data Explorer, you first create a cluster, and create one or more databases in that cluster. Then, you can ingest (load) data into a database and run queries against it.

In this article, you'll learn how to create a cluster and a database using either C#, Python, Go, the Azure CLI, PowerShell, or an Azure Resource Manager (ARM) template. To learn how to create a cluster and database using the Azure portal, see Quickstart: Create an Azure Data Explorer cluster and database.

For code samples based on previous SDK versions, see the archived article.

Prerequisites

Prerequisites by method of cluster and database creation:

Create an Azure Data Explorer cluster

This section guides you through the process of creating an Azure Data Explorer cluster. Choose the relevant tab for your preferred method to create the cluster.

  1. Create your cluster by using the following code:

    var tenantId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Directory (tenant) ID
    var clientId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx"; //Application ID
    var clientSecret = "PlaceholderClientSecret"; //Client Secret
    var subscriptionId = "xxxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxx";
    var credentials = new ClientSecretCredential(tenantId, clientId, clientSecret);
    var resourceManagementClient = new ArmClient(credentials, subscriptionId);
    var resourceGroupName = "testrg";
    var subscription = await resourceManagementClient.GetDefaultSubscriptionAsync();
    var resourceGroup = (await subscription.GetResourceGroupAsync(resourceGroupName)).Value;
    var clusters = resourceGroup.GetKustoClusters();    
    var clusterName = "mykustocluster";
    var skuName = KustoSkuName.StandardE8adsV5;
    var skuTier = KustoSkuTier.Standard;
    var capacity = 5;
    var clusterData = new KustoClusterData(
        location: AzureLocation.chinaeast2,
        sku: new KustoSku(skuName, skuTier) { Capacity = capacity }
    );
    await clusters.CreateOrUpdateAsync(WaitUntil.Completed, clusterName, clusterData);
    
    Setting Suggested value Field description
    clusterName mykustocluster The desired name of your cluster.
    skuName Standard_D13_v2 The SKU that will be used for your cluster.
    tier Standard The SKU tier.
    capacity number The number of instances of the cluster.
    resourceGroupName testrg The resource group name where the cluster will be created.

    Note

    Create a cluster is a long running operation, so it's highly recommended to use CreateOrUpdateAsync, instead of CreateOrUpdate.

  2. Run the following command to check whether your cluster was successfully created:

    clusterData = (await clusters.GetAsync(clusterName)).Value.Data;
    
  3. Confirm the successful creation of the cluster by verifying the result contains provisioningState as Succeeded.

Create an Azure Data Explorer database

In this section, you'll create a database within the cluster created in the previous section.

  1. Create your database by using the following code:

    var cluster = (await clusters.GetAsync(clusterName)).Value;
    var databases = cluster.GetKustoDatabases();
    var databaseName = "mykustodatabase";
    var softDeletePeriod = TimeSpan.FromDays(3650);
    var hotCachePeriod = TimeSpan.FromDays(3650);
    var databaseData = new KustoReadWriteDatabase
    {
        Location = clusterData.Location, SoftDeletePeriod = softDeletePeriod, HotCachePeriod = hotCachePeriod
    };
    await databases.CreateOrUpdateAsync(WaitUntil.Completed, databaseName, databaseData);
    

    Note

    If you are using C# version 2.0.0 or below, use Database instead of ReadWriteDatabase.

    Setting Suggested value Field description
    clusterName mykustocluster The name of your cluster where the database will be created.
    databaseName mykustodatabase The name of your database.
    resourceGroupName testrg The resource group name where the cluster will be created.
    softDeletePeriod 3650:00:00:00 The amount of time that data will be kept available to query.
    hotCachePeriod 3650:00:00:00 The amount of time that data will be kept in cache.
  2. Run the following command to see the database that you created:

    databaseData = (await databases.GetAsync(databaseName)).Value.Data as KustoReadWriteDatabase;
    

Next step