How to Trigger a DAG Manually in Apache Airflow
You can trigger a DAG manually in Airflow using the
airflow dags trigger command in the CLI or by clicking the Trigger DAG button in the Airflow web UI. Both methods start the DAG run immediately without waiting for the schedule.Syntax
The basic syntax to trigger a DAG manually using the CLI is:
airflow dags trigger [dag_id]- triggers the DAG with the given ID immediately.--run-id(optional) - specify a custom run ID for the DAG run.--conf(optional) - pass JSON configuration parameters to the DAG run.
bash
airflow dags trigger <dag_id> [--run-id <run_id>] [--conf '{"key":"value"}']Example
This example shows how to trigger a DAG named example_dag manually using the CLI and what output you will see.
bash
airflow dags trigger example_dag # Optional with run ID and conf airflow dags trigger example_dag --run-id manual__2024-06-01T12:00:00 --conf '{"param":"value"}'
Output
Created <DagRun example_dag @ 2024-06-01 12:00:00+00:00: manual__2024-06-01T12:00:00, externally triggered: True>
Common Pitfalls
- Trying to trigger a DAG that does not exist will cause an error:
DagNotFound. - Not having the Airflow environment properly initialized or the scheduler running may prevent the DAG from starting.
- Passing invalid JSON in
--confwill cause a parsing error. - Triggering a DAG via UI requires proper user permissions.
bash
Wrong: airflow dags trigger unknown_dag
# Error: DagNotFound: DAG 'unknown_dag' not found
Right: airflow dags trigger example_dagQuick Reference
Use this quick reference to trigger DAGs manually:
| Action | Command or UI Step |
|---|---|
| Trigger DAG via CLI | airflow dags trigger |
| Trigger DAG with custom run ID | airflow dags trigger |
| Trigger DAG with config | airflow dags trigger |
| Trigger DAG via UI | Go to Airflow Web UI โ DAGs โ Click Trigger DAG button |
Key Takeaways
Use
airflow dags trigger in CLI to start a DAG run immediately.You can add a custom run ID and JSON config with
--run-id and --conf options.The Airflow web UI also allows manual triggering with a simple button click.
Ensure the DAG exists and the scheduler is running to avoid errors.
Passing invalid JSON or wrong DAG IDs are common mistakes to avoid.