- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Hi @Sunioj ,
Both of your errors are caused by Databricks Free Edition compute limits and how databricks-sql-connector handles warehouse startups:
Error 1 (BAD_REQUEST: Cannot create the resource): Free Edition accounts only get one 2X-Small Serverless SQL Warehouse with a strict daily compute quota (and no capacity SLA). Because your AWS Lambda runs on a schedule, repeatedly waking or running the warehouse exhausts your daily free compute limit. Once that quota is reached (or when the shared free-tier pool is busy), Databricks blocks the warehouse from starting for the rest of the day—which is why retries also fail.
Why it works locally: When you test locally, you are usually running while you still have daily quota left or while the warehouse is already RUNNING in your browser.
Error 2 (400 Bad Request on /start): First, you don't need this API call—sql.connect() automatically wakes up a stopped SQL Warehouse. Second, response.raise_for_status() hides the real Databricks error message. Calling /start returns a 400 either because your daily Free Edition quota is exhausted (you can verify this by printing response.text), or because databricks_host is missing https:// (sql.connect expects a bare hostname, while requests.post requires https://).
How to fix it:
Remove the /start API call: Let sql.connect() start the warehouse automatically, set your Lambda timeout to at least 60–120 seconds for cold starts, and use a with sql.connect(...) as conn: block so connections close properly.
Reduce your schedule frequency: Set your SQL Warehouse Auto Stop to the minimum (5–10 minutes) in the UI and run your Lambda less frequently (e.g., hourly or once a day) so you don't burn through your daily Free Edition quota.
Pull from S3 instead of pushing from Lambda: Instead of waking up the warehouse from Lambda for small inserts, consider using a scheduled Databricks Job with Auto Loader or COPY INTO to pull new files directly from S3 in batches—it uses a fraction of the compute time.