Airflow Fundamentals study materials
Airflow Fundamentals study resources

Airflow Fundamentals: The Airflow CLI

Airflow Fundamentals · Work through your exam, one topic at a time.

All guide sections

The Airflow CLI

What the CLI is for

The airflow command-line tool wraps the same metadata database and components the UI uses, which makes it essential for automation and debugging on servers without a browser. Core subcommands a candidate should recognize:

  • airflow dags list - DAGs the scheduler has parsed; airflow dags list-runs -d my_dag - run history.
  • airflow tasks test my_dag my_task 2024-01-01 - run a single task locally without recording state in the database (great for debugging logic).
  • airflow tasks run and airflow tasks states-for-dag-run - execute or inspect task instances.
  • airflow dags trigger -d my_dag and airflow dags backfill - start runs.
  • airflow db init / airflow db migrate - initialize or upgrade the metadata schema.
  • airflow connections add and airflow variables set - manage configuration from the terminal.
  • airflow scheduler, airflow webserver, airflow dag-processor, airflow triggerer - start components.

Traps to watch

The biggest trap is tasks test versus tasks run: test executes the callable in isolation, ignores the scheduler, does not write task state, and does not respect dependencies or pools the same way, so it is a debugging aid, not a production trigger. Another trap is expecting CLI commands to work without a reachable metadata database - most fail fast if the DB is uninitialized or the connection string is wrong. Also note that dags list reflects parsed DAGs; a syntax error means the DAG silently disappears from the list rather than erroring loudly.

Rule of thumb

Use tasks test to prove your Python logic; use the UI or dags trigger when you need a real, recorded run with dependencies.