Sub topic 1
What Asset Bundles are and why to use them
A Databricks Asset Bundle is a project made of YAML configuration files and source code. The configuration describes Databricks resources such as jobs and pipelines. The Databricks CLI reads that configuration and creates or updates those resources in a workspace. This chapter covers the working model of a bundle and the problems it solves. Later chapters cover the syntax in detail.
Prerequisites
This chapter assumes you have:
- Basic familiarity with the Databricks workspace, notebooks, and jobs.
- Working knowledge of YAML syntax.
- Basic Git and command-line usage.
- A Databricks workspace where you can create jobs.
The problem bundles solve
Many teams build Databricks jobs by clicking through the workspace UI. This works for a first job, but it causes problems as a project grows:
- The job definition lives only in the workspace. Nothing in Git records who changed the cluster size or the schedule.
- Copying a job from a dev workspace to a prod workspace means redoing each setting by hand. Small differences creep in.
- Rebuilding a job after someone deletes it means remembering every setting.
- Code review covers the notebooks but not the job configuration that runs them.
Infrastructure as code addresses these problems. You describe the desired state of your resources in text files, keep those files in source control, and let a tool make the workspace match them. Asset Bundles apply this idea to Databricks.
The working model
A bundle has three parts that work together.
- Source code. Notebooks, Python files, SQL files, and tests, kept in your repository as usual.
- Configuration. A root file named
databricks.ymlplus optional extra YAML files. They declare the bundle name, the resources to create, and the deployment targets. - The Databricks CLI. It validates the configuration, uploads the files, and creates or updates the resources through the Databricks APIs.
A deployment target is a named environment, such as dev or prod. One bundle can define several targets. Each target can point at a different workspace and override settings.
The bundle describes the desired state. When you deploy, the CLI compares that state with what it previously deployed and applies the difference. You change the YAML, not the live resource.
A minimal example
The smallest useful bundle is a databricks.yml that names the bundle and declares a target:
bundle:
name: my_project
targets:
dev:
mode: development
default: true
workspace:
host: https://<your-dev-workspace-url>Resources are added under a resources key, either in this file or in files pulled in with include. A job resource looks like this:
resources:
jobs:
daily_etl:
name: daily_etl
tasks:
- task_key: ingest
notebook_task:
notebook_path: ../src/ingest.pyThe notebook path is relative to the YAML file that contains it. The CLI uploads the notebook when you deploy, and the job points at the uploaded copy.
What you gain
| Benefit | How bundles provide it |
|---|---|
| History and review | Configuration is in Git, so changes go through pull requests. |
| Repeatability | The same files produce the same job in any workspace you target. |
| Environment differences in one place | Targets and variables override only what differs between dev and prod. |
| Automation | The CLI runs the same commands on your laptop and in a CI/CD pipeline. |
| Clean removal | The CLI can delete everything it deployed for a target. |
Common mistakes
- Editing a deployed job in the UI. The next deploy overwrites the change, because the bundle is the source of truth. Make the change in YAML.
- Treating a bundle as a notebook sync tool. A bundle also manages resources, not only files. Resource definitions are the main reason to use one.
- Hard-coding workspace-specific values. Cluster node types and catalog names differ across clouds and environments. Use variables, covered in a later chapter.
Exercises
Exercise
A teammate changes the schedule of a bundle-deployed job directly in the workspace UI. What happens at the next databricks bundle deploy, and what should the teammate have done instead?
Show answer
The deploy sets the job back to the schedule in the YAML, so the UI change is lost. The teammate should edit the schedule in the bundle's YAML, open a pull request, and deploy from there.
Exercise
Name the three parts of a bundle and say what each one does.
Show answer
Source code (notebooks and files that do the work), configuration (databricks.yml and other YAML files that declare resources and targets), and the Databricks CLI (validates the configuration, uploads files, and creates or updates resources).