Databricks Apps configuration

Important

Databricks Apps is in Public Preview.

This article details the settings automatically configured in the Databricks Apps environment and explains how to define custom configuration required for your apps.

The Databricks Apps environment sets several environment variables, such as the URL of the Azure Databricks workspace running the app and values required to perform authentication for your app. However, sometimes your apps will require additional custom variables. For example, you might need a custom command to run your app or parameters to connect to a SQL warehouse. For these custom configuration parameters, use the app.yaml file.

Configuring your Databricks apps with the app.yaml file

Note

Your app configuration file can use the .yaml or .yml extension.

To define custom configuration for your app, add an app.yaml file to your project. The following table shows the settings you can define in the app.yaml file, followed by example configuration files.

app.yaml settings
command

Type: sequence

An optional set of arguments to run your app. Use this setting when you require a custom command to run your app. The default values are [python, app.py].

The command is not run in a shell, so any values set in the environment are not passed to your app. If your app requires additional parameters to run, use the env structure.

This setting is optional.
env

Type: list

The top-level key for an optional list of key-value pairs that define environment variables to pass to your app. The value can be either an actual parameter value or a reference to where the value is stored. The valid items in the list are:

- name: The name of the environment variable.
- One of:
- value: The value for the environment variable.
- valueFrom: For an externally defined value, the name of the source containing the value. For example, the name of a secret or a database table containing the value.

This setting is optional.

Example app.yaml for a Streamlit app

The following example app.yaml configuration file runs a Streamlit app, passing in a SQL warehouse ID and a value for the STREAMLIT_GATHER_USAGE_STATS parameter:

command: [
  "streamlit",
  "run",
  "app.py"
]
env:
  - name: "DATABRICKS_WAREHOUSE_ID"
    value: "quoz2bvjy8bl7skl"
  - name: "STREAMLIT_GATHER_USAGE_STATS"
    value: "false"

Example app.yaml for a Flask app

The following example app.yaml configuration file runs a Flask app with the Gunicorn server and sets an environment variable containing the path to a Unity Catalog volume:

command:
  - gunicorn
  - app:app
  - -w
  - 4
env:
  - name: "VOLUME_URI"
    value: "/Volumes/catalog-name/schema-name/dir-name"

Reference a Databricks secret

To reference a secret configured as a resource dependency for your app, set valueFrom: <dependency_name> in the env section of your app.yaml configuration. Replace dependency_name with the resource key value from the configuration for the secret resource. To learn more about Databricks Apps resource dependencies, see How do I integrate my Databricks app with Azure Databricks services?. To learn more about managing Databricks secrets, see Secrets.

The following example app.yaml references a secret configured as a resource dependency:

command: [
  "python",
  "app.py"
]
env:
  - name: "SECRET_KEY"
    valueFrom: "secret-name"

Databricks Apps environment variables

The following variables are automatically set in the Databricks Apps environment and available to all apps. If you need to set additional environment variables, add them to the app.yaml file.

Variable Description
DATABRICKS_APP_NAME The name of the running app.
DATABRICKS_WORKSPACE_ID The unique ID for the Databricks workspace the app belongs to.
DATABRICKS_HOST The URL of the Databricks workspace to which the app belongs.
DATABRICKS_APP_PORT The network port the app should listen on.
DATABRICKS_CLIENT_ID The client ID for the Databricks service principal assigned to the app.
DATABRICKS_CLIENT_SECRET The OAuth secret for the Databricks service principal assigned to the app.

Default environment variables for Streamlit

The following Streamlit-specific variables are automatically configured in the Databricks Apps environment and available to your Databricks apps that use the Streamlit framework:

Variable Description
STREAMLIT_SERVER_ADDRESS The server address for use by Streamlit. This value is set to 0.0.0.0 and must not be overridden.
STREAMLIT_SERVER_PORT The port for use by Streamlit. This value is set to DATABRICKS_APP_PORT and must not be overridden.
STREAMLIT_SERVER_ENABLE_XSRF_PROTECTION Because the Databricks Apps reverse proxy protects against Cross-Site Request Forgery (XSRF), this is set to false.
STREAMLIT_SERVER_ENABLE_CORS Because the Databricks Apps reverse proxy protects against Cross-Origin Resource Sharing (CORS), This is set to false.
STREAMLIT_SERVER_HEADLESS This is set to true so Streamlit runs without opening a browser window when starting.
STREAMLIT_BROWSER_GATHER_USAGE_STATS This is set to false to prevent sending user stats to Streamlit.