Issue while creating on-demand cluster in azure databricks using pyspark

vivek_cloudde
New Contributor III

Hello,

I am trying to create an on demand cluster in azure databricks using below code and i am getting the error message
{"error_code":"INVALID_PARAMETER_VALUE","message":"Exactly 1 of virtual_cluster_size, num_workers or autoscale must be specified.","details":[{"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"CM_API_ERROR_SOURCE_CALLER_ERROR","domain":""}]}
I tried different settings multiple times and still getting the same error every time. Can someone please help me resolve this issue? As per my understanding it is not possible to create ondemand cluster with auto scale capabilities. Can someone please confirm if my understanding is correct?

import requests
import json

clusterConfig={
"new_cluster": {
        "spark_version": "15.4.x-scala2.12",
        "effective_spark_version": "15.4.x-cpu-ml-scala2.12",
        "node_type_id": "Standard_D14_v2",
        "spark_conf": {
            "spark.databricks.delta.preview.enabled": True
        },
        "custom_tags": {
            "ResourceClass": "SingleNode"
        },
        "azure_attributes": {
            "first_on_demand": 1,
            "availability": "ON_DEMAND_AZURE",
            "spot_bid_max_price": "-1"
        },
        "enable_elastic_disk": True,
        "num_workers": 2,
        "autotermination_minutes": 10
    }
}

# Initialize the DatabricksAPI with your workspace URL and token
workspaceUrl = "https://###########.azuredatabricks.net"
databricksToken = dbutils.secrets.get(scope="##############", key="dbx-token")

# Headers for the API request
headers = {
    "Authorization": f"Bearer {databricksToken}",
    "Content-Type": "application/json"
}

try:
  # Send the API request to create the cluster
  response = requests.post(
      f"{workspaceUrl}/api/2.0/clusters/create",
      headers=headers,
      data=json.dumps(clusterConfig)
  )

  if response.status_code == 200:
    # Extract the cluster_id from the response
    cluster_data = response.json()
    cluster_id = cluster_data["cluster_id"]
    print(f"Cluster created successfully! Cluster ID: {cluster_id}")
  else:
    print(f"Error creating cluster: {response.status_code}, {response.text}")
except Exception as e:
  print("ErrorMessage:" + str(e))

 Thanks