---
title: Declarative Automation Bundles for MLOps Stacks
description: Learn about how to use Declarative Automation Bundles to work with MLOps Stacks.
canonical_url: https://docs.databricks.com/aws/en/dev-tools/bundles/mlops-stacks
---

# Declarative Automation Bundles for MLOps Stacks

You can use Declarative Automation Bundles, the Databricks CLI, and the [Databricks MLOps Stack](https://github.com/databricks/mlops-stack) repository on GitHub to create *MLOps Stacks*. An MLOps Stack is an [MLOps](https://docs.databricks.com/aws/en/machine-learning/mlops/mlops-workflow.md) project on Databricks that follows production best practices out of the box. See [What are Declarative Automation Bundles?](https://docs.databricks.com/aws/en/dev-tools/bundles/index.md).

This shows how to create, deploy, and run an MLOps Stacks bundle project.

## Requirements

* Make sure that the target remote workspace has workspace files enabled. See [What are workspace files?](https://docs.databricks.com/aws/en/files/workspace.md).
* On your development machine, make sure that Databricks CLI version 0.212.2 or above is installed. To check your installed Databricks CLI version, run the command `databricks -v`. To update your Databricks CLI version, see [Install or update the Databricks CLI](https://docs.databricks.com/aws/en/dev-tools/cli/install.md). (Bundles do not work with Databricks CLI versions 0.18 and below.)

## Step 1: Set up authentication

Configure the Databricks CLI for authentication.

This article assumes that you want to use OAuth user-to-machine (U2M) authentication and a corresponding Databricks configuration profile named `DEFAULT` for authentication.

> [!NOTE]
>
> U2M authentication is appropriate for trying out these steps in real time. For fully automated workflows, Databricks recommends that you use OAuth machine-to-machine (M2M) authentication instead. See the M2M authentication setup instructions in [Authorize Databricks service principal access to Databricks with OAuth](https://docs.databricks.com/aws/en/dev-tools/auth/oauth-m2m.md).

1. Use the [Databricks CLI](https://docs.databricks.com/aws/en/dev-tools/cli/install.md) to initiate OAuth token management locally by running the following command for each target workspace.

   In the following command, replace `<workspace-url>` with your Databricks [workspace instance URL](https://docs.databricks.com/aws/en/workspace/workspace-details.md#workspace-url), for example `https://dbc-a1b2345c-d6e7.cloud.databricks.com`.

   ```bash
   databricks auth login --host <workspace-url>
   ```

2. The Databricks CLI prompts you to save the information that you entered as a Databricks [configuration profile](https://docs.databricks.com/aws/en/dev-tools/auth/config-profiles.md). Press `Enter` to accept the suggested profile name, or enter the name of a new or existing profile. Any existing profile with the same name is overwritten with the information that you entered. You can use profiles to quickly switch your authentication context across multiple workspaces.

   To get a list of any existing profiles, in a separate terminal or command prompt, use the Databricks CLI to run the command `databricks auth profiles`. To view a specific profile's existing settings, run the command `databricks auth env --profile <profile-name>`.

3. In your web browser, complete the on-screen instructions to log in to your Databricks workspace.

4. To view a profile's current OAuth token value and the token's upcoming expiration timestamp, run one of the following commands:

   * `databricks auth token --host <workspace-url>`
   * `databricks auth token -p <profile-name>`
   * `databricks auth token --host <workspace-url> -p <profile-name>`

   If you have multiple profiles with the same `--host` value, you might need to specify the `--host` and `-p` options together to help the Databricks CLI find the correct matching OAuth token information.

## Step 2: Create the bundle project

1. Use [bundle templates](https://docs.databricks.com/aws/en/dev-tools/bundles/templates.md) to create your MLOps Stacks project's starter files. To do this, begin by running the following command:

   ```bash
   databricks bundle init mlops-stacks
   ```

2. Answer the on-screen prompts. For guidance on answering these prompts, see [Start a new project](https://github.com/databricks/mlops-stacks/blob/main/README.md#start-a-new-project) in the [Databricks MLOps Stacks](https://github.com/databricks/mlops-stacks) repository on GitHub.

   The first prompt offers the option of setting up the ML code components, the CI/CD components, or both. This option simplifies the initial setup as you can choose to create only those components that are immediately relevant. (To set up the other components, run the initialization command again.) Select one of the following:

   * `CICD_and_Project` (default) - Set up both ML code and CI/CD components.
   * `Project_Only` - Set up ML code components only. This option is for data scientists to get started.
   * `CICD_Only` - Set up CI/CD components only. This option is for ML engineers to set up infrastructure.

   After you answer all of the on-screen prompts, the template creates your MLOps Stacks project's starter files and adds them to your current working directory.

3. Customize your MLOps Stacks project's starter files as desired. To do this, follow the guidance in the following files within your new project:

   | Role                          | Goal                                                                                  | Docs                                 |
   | ----------------------------- | ------------------------------------------------------------------------------------- | ------------------------------------ |
   | First-time users of this repo | Understand the ML pipeline and code structure in this repo                            | `README.md`                          |
   | Data Scientist                | Get started writing ML code for a brand new project                                   | `<project-name>/README.md`           |
   | Data Scientist                | Update production ML code (for example, model training logic) for an existing project | `docs/ml-pull-request.md`            |
   | Data Scientist                | Modify production model ML resources (for example, model training or inference jobs)  | `<project-name>/resources/README.md` |
   | MLOps / DevOps                | Set up CI/CD for the current ML project                                               | `docs/mlops-setup.md`                |

   * For customizing experiments, the mappings within an experiment declaration correspond to the create experiment operation's request payload as defined in [POST /api/2.0/mlflow/experiments/create](https://docs.databricks.com/api/workspace/experiments/createexperiment) in the REST API reference, expressed in YAML format.

   * For customizing jobs, the mappings within a job declaration correspond to the create job operation's request payload as defined in [POST /api/2.1/jobs/create](https://docs.databricks.com/api/workspace/jobs/create) in the REST API reference, expressed in YAML format.

     > [!TIP]
     >
     > You can define, combine, and override the settings for new job clusters in bundles by using the techniques described in [Override with target settings](https://docs.databricks.com/aws/en/dev-tools/bundles/overrides.md).

   * For customizing models, the mappings within a model declaration correspond to the create Unity Catalog model operation's request payload as defined in [POST /api/2.1/unity-catalog/models](https://docs.databricks.com/api/workspace/registeredmodels/create) in the REST API reference, expressed in YAML format.

   * For customizing pipelines, the mappings within a pipeline declaration correspond to the create pipeline operation's request payload as defined in [POST /api/2.0/pipelines](https://docs.databricks.com/api/workspace/pipelines/create) in the REST API reference, expressed in YAML format.

## Step 3: Validate the bundle project

Check whether the bundle configuration is valid. To do this, run the Databricks CLI from the project's root, where the `databricks.yml` is located, as follows:

```bash
databricks bundle validate
```

If a summary of the bundle configuration is returned, then the validation succeeded. If any errors are returned, fix the errors, and then repeat this step.

## Step 4: Deploy the bundle

Deploy the project's resources and artifacts to the desired remote workspace. To do this, run the Databricks CLI from the project's root, where the `databricks.yml` is located, as follows:

```bash
databricks bundle deploy -t <target-name>
```

Replace `<target-name>` with the name of the desired target within the `databricks.yml` file, for example `dev`, `test`, `staging`, or `prod`.

## Step 5: Run the deployed bundle

The project's deployed jobs automatically run on their predefined schedules. To run a deployed job immediately, run the Databricks CLI from the project's root, where the `databricks.yml` is located, as follows:

```bash
databricks bundle run -t <target-name> <job-name>
```

* Replace `<target-name>` with the name of the desired target within the `databricks.yml` file where the job was deployed, for example `dev`, `test`, `staging`, or `prod`.
* Replace `<job-name>` with the name of the job in one of the `.yml` files within `<project-name>/databricks-resources`, for example `batch_inference_job`, `write_feature_table_job`, or `model_training_job`.

A link to the Databricks job appears, which you can copy into your web browser to open the job within the Databricks UI.

## Step 6: Delete the deployed bundle (optional)

To delete a deployed project's resources and artifacts if you no longer need them, run the Databricks CLI from the project's root, where the `databricks.yml` is located, as follows:

```bash
databricks bundle destroy -t <target-name>
```

Replace `<target-name>` with the name of the desired target within the `databricks.yml` file, for example `dev`, `test`, `staging`, or `prod`.

Answer the on-screen prompts to confirm the deletion of the previously deployed resources and artifacts.
