Sub topic 1
Why Automate Databricks, and Which Tool to Use
Prerequisites
Assume you can use a shell, set environment variables, read JSON, and run basic Python. You should also know what a Databricks workspace, job, and cluster are.
Why Automate Databricks?
Automation makes workspace actions repeatable. Scripts can start jobs on a schedule, deploy the same configuration across environments, and record failures for CI/CD (continuous integration and delivery). Automation also reduces manual clicks and configuration drift.
Choose the tool that matches the task:
| Tool | Best use |
|---|---|
| Databricks CLI | Interactive administration and shell scripts |
| REST API | Direct HTTP integration or an unsupported CLI operation |
| Python SDK | Typed Python programs and pagination |
| Asset Bundles | Jobs and related resources defined as code |
Installing the Databricks CLI
Install the current CLI with your platform's package manager. For example:
brew install databricks
databricks -vKeep the CLI updated. Command names and authentication behavior can differ between old and current CLI releases.
Authenticating
OAuth is the preferred interactive method. The CLI opens a browser, stores a profile, and uses a short-lived credential flow.
databricks auth login --host https://<workspace-host>
databricks current-user me
databricks auth profilesA personal access token (PAT) is a secret string used by a program instead of a browser login. Use a PAT only when OAuth is unsuitable, such as a controlled script. Give it the smallest required permissions and store it in a secret manager.
export DATABRICKS_HOST="https://<workspace-host>"
export DATABRICKS_TOKEN="<token>"
databricks current-user meProfiles and Environment Variables
A profile is a named set of connection settings. Profiles are useful when one person or pipeline accesses multiple workspaces. Environment variables are convenient for temporary use and usually override profile selection.
databricks auth profiles
databricks current-user me --profile production
databricks jobs list --profile productionCore CLI Command Groups
Common groups include auth for credentials, current-user for identity, jobs for job operations, clusters for compute, workspace for workspace files, and bundle for deployments. Add --output json when another command must process the result.
databricks jobs list --output jsonExercise
Which tool is usually the best fit for defining and deploying a job from version control?
Show answer
Databricks Asset Bundles, because they represent resources as configuration and support repeatable deployment.