-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_sql_warehouse.py
More file actions
50 lines (41 loc) · 1.39 KB
/
create_sql_warehouse.py
File metadata and controls
50 lines (41 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# Databricks notebook source
# MAGIC %pip install -qq mlflow==2.16.1
# COMMAND ----------
import requests
import json
import mlflow
# COMMAND ----------
# Set your Databricks workspace URL and personal access token
workspace_url = mlflow.utils.databricks_utils.get_databricks_host_creds().host
print(workspace_url)
token = dbutils.notebook.entry_point.getDbutils().notebook().getContext().apiToken().get() # os.getenv("DATABRICKS_TOKEN")
# API endpoint for creating a warehouse
api_endpoint = f"{workspace_url}/api/2.0/sql/warehouses"
# Define the warehouse configuration
warehouse_config = {
"name": "david_test_Warehouse",
"cluster_size": "2X-Small",
"min_num_clusters": 1,
"max_num_clusters": 1,
"auto_stop_mins": 20,
"enable_photon": True,
"warehouse_type": "PRO",
"spot_instance_policy": "COST_OPTIMIZED",
"channel": {
"name": "CURRENT"
}
}
# Set up the request headers
headers = {
"Authorization": f"Bearer {token}",
"Content-Type": "application/json"
}
# Send the POST request to create the warehouse
response = requests.post(api_endpoint, headers=headers, data=json.dumps(warehouse_config))
# Check the response
if response.status_code == 200:
print("Warehouse created successfully!")
print(json.dumps(response.json(), indent=2))
else:
print(f"Failed to create warehouse. Status code: {response.status_code}")
print(response.text)