Connecting to dbt Cloud¶
After installing the dbt Cloud provider in your Airflow environment, the corresponding connection type of
dbt_cloud
will be made available. The following describes how to configure an API token and optionally
provide an Account ID and/or a Tenant name for your dbt Cloud connection.
Default Connection ID¶
All hooks and operators related to dbt Cloud use dbt_cloud_default
by default.
Authenticating to the dbt Cloud API¶
To interact with the dbt Cloud API in Airflow, either a User API Token or a Service Account API Token is required.
Configuring the connection¶
- Password (required)
The API token to use when authenticating to the dbt Cloud API.
If using the Connection form in the Airflow UI, the token can also be stored in the “API Token” field.
- Login (optional)
The Account ID to be used as the default Account ID for dbt Cloud operators or
DbtCloudHook
methods. If an Account ID is provided in the connection, you are not required to passaccount_id
to operators or hook methods. Theaccount_id
value will be retrieved from the Airflow connection instead. If needed, theaccount_id
can still be explicitly passed to an operator or hook method as an override the default value configured in the connection.If using the Connection form in the Airflow UI, the Account ID can also be stored in the “Account ID” field.
Note
If an Account ID is not provided in an Airflow connection,
account_id
must be explicitly passed to an operator or hook method.- Host (optional)
The Tenant domain for your dbt Cloud environment (e.g. “my-tenant.getdbt.com”). This is particularly useful when using a single-tenant dbt Cloud instance or other dbt Cloud regions like EMEA or a Virtual Private dbt Cloud. If a Tenant domain is not provided, “cloud.getdbt.com” will be used as the default value assuming a multi-tenant instance in the North America region.
If using the Connection form in the Airflow UI, the Tenant domain can also be stored in the “Tenant” field.
- Extra (optional)
Specify extra parameters as JSON dictionary. As of now, only proxies is supported when wanting to connect to dbt Cloud via a proxy.
proxies should be a dictionary of proxies to be used by HTTP and HTTPS connections.
{
"proxies": {
"http": "http://myproxy.mycompany.local:8080",
"https": "http://myproxy.mycompany.local:8080"
}
}
When specifying the connection as an environment variable, you should specify it following the standard syntax of a database connection. Note that all components of the URI should be URL-encoded.
For example, to add a connection with the connection ID of “dbt_cloud_default”:
When specifying an Account ID:
export AIRFLOW_CONN_DBT_CLOUD_DEFAULT='dbt-cloud://account_id:api_token@'When not specifying an Account ID:
export AIRFLOW_CONN_DBT_CLOUD_DEFAULT='dbt-cloud://:api_token@'When specifying a Tenant domain, be sure to follow the Access URL pattern in the table [here](https://docs.getdbt.com/docs/cloud/about-cloud/access-regions-ip-addresses)
export AIRFLOW_CONN_DBT_CLOUD_DEFAULT='dbt-cloud://:api_token@my-access-url'As an example, if my account is hosted in the Cell-based North America region and my access URL is ab123.us1.dbt.com, my conn string should be: .. code-block:: bash
export AIRFLOW_CONN_DBT_CLOUD_DEFAULT=’dbt-cloud://:api_token@ab123.us1.dbt.com’
You can refer to the documentation on creating connections via environment variables for more information.