Databricks Apps configuration
Preview
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 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.
|
---|
Type: 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 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 This setting is optional. |
Type: The top-level key for an optional list of key-value pairs that define environment variables to pass to your
app. The
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 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 |
---|---|
|
The name of the running app. |
|
The unique ID for the Databricks workspace the app belongs to. |
|
The URL of the Databricks workspace to which the app belongs. |
|
The network port the app should listen on. |
|
The client ID for the Databricks service principal assigned to the app. |
|
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 |
---|---|
|
The server address for use by Streamlit. This value is set to 0.0.0.0 and must not be overridden. |
|
The port for use by Streamlit. This value is set to DATABRICKS_APP_PORT and must not be overridden. |
|
Because the Databricks Apps reverse proxy protects against Cross-Site Request Forgery (XSRF), this is set to |
|
Because the Databricks Apps reverse proxy protects against Cross-Origin Resource Sharing (CORS), This is set to |
|
This is set to |
|
This is set to |