Skip to main content

Connect Databricks App to Databricks App

This recipe demonstrates how to connect from a Databricks App to an API hosted as another Databricks App.

info

This is another type of Machine-to-Machine (M2M) connectivity. As each Databricks App is assigned a dedicated service principal upon creation, you should use this service principal's credentials when interacting with any Databricks service, including other Databricks Apps.

Code snippet

In the Databricks Apps environment, environment variables for DATABRICKS_HOST, DATABRICKS_CLIENT_ID, and DATABRICKS_CLIENT_SECRET are are automatically set based on the app's workspace and assigned service principal. Therefore, you do not need to explicitly specify these values in the following code:

from databricks.sdk import WorkspaceClient
import requests

# DATABRICKS_HOST, DATABRICKS_CLIENT_ID, DATABRICKS_CLIENT_SECRET available in environemnt
wc = WorkspaceClient()
headers = wc.config.authenticate() # Contains Bearer Token

response = requests.get(
"https://your-app-url/api/v1/healthcheck", headers=headers
)
print(response.json())

Permissions

For Databricks App connectivity and authentication, the connecting App service principal needs the following permissions:

  • CAN USE on the target app

Dependencies

requirements.txt
databricks-sdk
requests