Monday 7 March 2022

Airflow Connection Code Example - Access connection data from code

 Here's a straight forward piece of code, but I found this solution difficult to find and uncover .  So here's the solution to getting the data from the Airflow connection in to my DAG - in Google Cloud Platform 


from airflow.hooks.base_hook import BaseHook

conn = BaseHook.get_connection('my_conn')

def connect_to_somewhere():
logging.info(conn.login)
logging.info(conn.password)



Hope that helps someone out there ! 

No comments: