Airflow Examples
This directory contains example Airflow DAGs and helper scripts.
Files
simple_data_pipeline.py- A basic ETL pipeline DAG demonstrating task dependencies and XComrun_dag.sh- Script to test and run DAGs manuallyrequirements.txt- Python dependencies for Airflow
Setup
- Install Airflow:
pip install -r requirements.txt - Initialize Airflow database:
airflow db init - Create an admin user:
airflow users create \ --username admin \ --firstname Admin \ --lastname User \ --role Admin \ --email admin@example.com \ --password admin - Copy the DAG file to your Airflow dags folder:
cp simple_data_pipeline.py ~/airflow/dags/ - Start Airflow:
# Terminal 1: Start webserver airflow webserver --port 8080 # Terminal 2: Start scheduler airflow scheduler - Access the UI at http://localhost:8080 (username:
admin, password:admin)
Running the Example
- The DAG will appear in the Airflow UI within a few minutes
- Toggle it ON to enable scheduling
- Click the play button to trigger a manual run
- Monitor the execution in the UI
Testing the DAG
Test the DAG without running it:
airflow dags test simple_data_pipeline 2024-01-01
Or use the provided script:
chmod +x run_dag.sh
./run_dag.sh simple_data_pipeline
Additional Resources
For comprehensive documentation, tutorials, and additional resources, see the Airflow documentation page.