Monday
Hello there!
I have been using the databricks-sdk for a while, and I have managed to create a system where I have controlled when the clusters and applications start and stop.
However, now that we have adopted the new lakebase feature, we were wondering if we can do the same for those instances.
In the documentation (https://databricks-sdk-py.readthedocs.io/en/latest/dbdataclasses/database.html#databricks.sdk.servic...), I cannot see anything similar to what exists for applications and clusters.
For more context, we have scheduled a job that stops one of our applications doing the following:
if action == "stop" and cluster_status == "RUNNING":
print(f"Stopping cluster_id {cluster_id}")
w.clusters.delete(cluster_id)
elif action == "start" and cluster_status == "STOPPED":
print(f"Starting cluster_id {cluster_id}")
w.clusters.start(cluster_id)
By having the cluster_id, we can start or stop the cluster automatically.
Does anyone from this community know how can we achieve something similar but for lakebase instances?
Thanks in advance
Monday - last edited Monday
Sure, @juanjomendez96 . You just need to use following code from python SDK:
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.database import DatabaseInstance
# Initialize the Workspace client
w = WorkspaceClient()
# Stop a database instance
instance_name = "my-database-instance"
w.database.update_database_instance(
name=instance_name,
database_instance=DatabaseInstance(
name=instance_name,
stopped=True
),
update_mask="*"
)
print(f"Stopped database instance: {instance_name}")
# Start a database instance
w.database.update_database_instance(
name=instance_name,
database_instance=DatabaseInstance(
name=instance_name,
stopped=False
),
update_mask="*"
)
print(f"Started database instance: {instance_name
Monday
Hello @juanjomendez96
I believe this documentation covers exactly what you’re looking for. Just keep in mind that this feature is still in Public Preview, and as highlighted at the top of the page, it may not yet be available in your region.
"This feature is in Public Preview in the following regions: us-east-1, us-west-2, eu-west-1, ap-southeast-1, ap-southeast-2, eu-central-1, us-east-2, ap-south-1."
Hope this helps 🙂
Isi
Monday
Hello @Isi thanks for your fast response in the matter. Actually I have lakebase enabled in my region, the only problem was that I did not fully understand the documentation.
Thanks anyways 😉
Monday - last edited Monday
Sure, @juanjomendez96 . You just need to use following code from python SDK:
from databricks.sdk import WorkspaceClient
from databricks.sdk.service.database import DatabaseInstance
# Initialize the Workspace client
w = WorkspaceClient()
# Stop a database instance
instance_name = "my-database-instance"
w.database.update_database_instance(
name=instance_name,
database_instance=DatabaseInstance(
name=instance_name,
stopped=True
),
update_mask="*"
)
print(f"Stopped database instance: {instance_name}")
# Start a database instance
w.database.update_database_instance(
name=instance_name,
database_instance=DatabaseInstance(
name=instance_name,
stopped=False
),
update_mask="*"
)
print(f"Started database instance: {instance_name
Monday
Hello @szymon_dybczak this worked like a charm. Thanks a lot!
Monday
No problem @juanjomendez96 🙂
Passionate about hosting events and connecting people? Help us grow a vibrant local community—sign up today to get started!
Sign Up Now