Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
Showing results for 
Search instead for 
Did you mean: 

How to change cluster size using a script


I want to change instance type or number of max workers via a python script. Does anyone know how to do it/is it possible? I have a lot of background jobs when I want to scale down my workers, so autoscaling is not an option.


I was getting an error that node_type_id value must be Standard_DS3_v2 but that is my current one that I want to change

Failed to update cluster size. Status code: 400, Response: {"error_code":"INVALID_PARAMETER_VALUE","message":"Validation failed for node_type_id, the value must be Standard_DS3_v2 (is \"Standard_DS4_v2\")","details":[{"@type":"","field_violations":[{"field":"node_type_id","description":"Validation failed for node_type_id, the value must be Standard_DS3_v2 (is \"Standard_DS4_v2\")"}]},{"@type":"","reason":"CM_API_ERROR_SOURCE_CALLER_ERROR","domain":""}]}


Valued Contributor

We can update cluster configuration prgramatically using databricks api. 


 1) Fetch all the clusters info present in your workspace.

 2) Loop through each cluster info

 3) Use the parsed info like cluster id etc.. to update cluster config

Example Psuedo code:

import requests
import json

host = "https://<YOUR-WORKSPACE-URL>"
workspace_access_token = "<YOUR-ACCESS-TOKEN>"
cluster_id = "<YOUR-CLUSTER-ID>"
workers_min = 1
workers_max = 2

response =
            "Authorization": f"Bearer {workspace_access_token}",
"Content-Type": "application/json"
"cluster_id": cluster_id,
"min_workers": workers_min,
"max_workers": workers_max


Valued Contributor III

Hi ksenija, this is just my guess but maybe you are using Cluster Policy in your cluster that only allows you to use specific cluster size ? E.g. below cluster policy that limits to some cluster sizes only.




Yes, you can only use the node types specified in the policy.

You're right, I didn't even check policies. This means I can't even change min and max workers, right?



Valued Contributor III

Correct, please look at my example:
- i have created policy with fixed min and max no. of workers


Even UI block me and won;t allow to change min and max no. of workers


So your script will fail as it is violating cluster ploticy 

Join 100K+ Data Experts: Register Now & Grow with Us!

Excited to expand your horizons with us? Click here to Register and begin your journey to success!

Already a member? Login and join your local regional user group! If there isn’t one near you, fill out this form and we’ll create one for you to join!