Airflow Variables Decoded: Maximizing workflow efficiency
Vidushraj Chandrasekaran
Data Engineer???? | GCP Certified Data Engineer | MS Certified Data Engineer | 6x Azure | Data Engineering | BSc (Hons) in EEE | AMIE(SL) | AEng(ECSL)
Variables play a pivotal role in enhancing workflow flexibility and security. They enable dynamic parameterization and confidential data handling across DAGs, making task orchestration a smooth process. Now it's time to get an understanding of variables configuring, retrieving, mask sensitive data, and effectively harnessing the power of variables in Airflow.
Configuring Variables
Airflow UI offers a user-friendly interface to configure and manage variables. Kindly check the screenshots below for your reference.
Click Admin Tab ->
Click Variables to define ->
Saving a variable ->
Retrieving the variable
from airflow.models import Variable
xyz = Variable.get("XYZ")
Masking Sensitive Data:
For sensitive information like passwords or API keys, Airflow provides a secure method to encrypt and decrypt these values. Set the variable with json.dumps()
import json
masked_data = {
"password": "my_secret_password"
}
Variable.set("masked_variable",json.dumps(masked_data),serialize_json=true)
Or in Airflow UI when you configure a Key name as Password it will automatically mask the value.
Conclusion:
Leveraging variables in Apache Airflow significantly streamlines workflow management. By configuring, retrieving, and securely handling sensitive information, you enhance DAG flexibility and maintain data integrity.
Airflow's variable configuration will help you optimize your workflows, ensuring smoother and more efficient task execution.
Happy Airflowing!