Search code examples
azureairflowazure-storageconnection-string

Retrieve azure blob storage connection string from airflow connection id


I am trying to see how can I retrieve the azure connection string value stored in airflow as a connection ID.

I have called the azure blob storage connection id using azure_conn as shown below. I am trying to see how can I return back the connection string from this variable azure_conn

azure_conn = WasbHook(wasb_conn_id='wasb_conn_id')

The variable azure_conn is of type

<class 'airflow.providers.microsoft.azure.hooks.wasb.WasbHook'>

Solution

  • The WasbHook has access to a get_connection() method inherited from the BaseHook (see here). You can instantiate the WasbHook as you do now and then call the get_connection() method to retrieve attributes from the Azure Blob Storage Connection you setup.

    hook = WasbHook(wasb_conn_id='wasb_conn_id')
    conn = hook.get_connection(hook.conn_id)
    print(conn.extra_dejson) # To retrieve the connection string