Learning Platform
Глоссарий Troubleshooting
Урок 14.01 · 10 мин
Продвинутый
REST APICLIAuthenticationAutomation

REST API и CLI — обзор модуля

В Airflow 2.0 стал stable REST API v1 на Flask-RESTful. Это позволяет автоматизировать всё через HTTP: trigger DAGs, monitor execution, clear tasks, manage Connections. Этот модуль учит правильно использовать API в CI/CD контексте.

Уроки модуля

#УрокЧто внутри
01Обзор модуляТекущий урок
02REST API v1 endpoints/api/v1/* — основные endpoints
03Authentication: basic, JWT, OAuthFAB auth backends
04Common automation patternsTrigger DAGs externally, monitor state, clear
05CLI deep diveairflow dags / tasks / db / pools / connections
06Programmatic accessPython client, custom scripts

REST API v1 — ключевые endpoints

# Trigger DAG run
POST /api/v1/dags/{dag_id}/dagRuns
{
  "logical_date": "2026-05-12T00:00:00Z",
  "conf": {"key": "value"}
}

# Get DAG run state
GET /api/v1/dags/{dag_id}/dagRuns/{dag_run_id}

# List TaskInstances
GET /api/v1/dags/{dag_id}/dagRuns/{run_id}/taskInstances

# Clear tasks
POST /api/v1/dags/{dag_id}/clearTaskInstances

OpenAPI 3 spec доступен на /api/v1/openapi.yaml.

Authentication backends

[api]
auth_backends = airflow.api.auth.backend.basic_auth,airflow.api.auth.backend.session

Доступные backends:

  • basic_auth — HTTP Basic с FAB users
  • session — cookie-based (для AJAX из UI)
  • kerberos_auth
  • airflow.providers.amazon.aws.auth_manager.aws_auth_manager — AWS IAM (через MWAA)

Common automation patterns

Trigger DAG из external system

curl -X POST \
  -u airflow:airflow \
  -H "Content-Type: application/json" \
  -d '{"conf": {"source_path": "s3://..."}}' \
  http://airflow:8080/api/v1/dags/my_dag/dagRuns

Monitor execution

curl -u airflow:airflow \
  http://airflow:8080/api/v1/dags/my_dag/dagRuns/manual__2026-05-12T10:00:00 \
  | jq '.state'

Из Python через requests

import requests
from requests.auth import HTTPBasicAuth

response = requests.post(
    "http://airflow:8080/api/v1/dags/my_dag/dagRuns"
    auth=HTTPBasicAuth("airflow", "airflow"),
    json={"conf": {"date": "2026-05-12"}}
)

Killer takeaway

Для CI/CD integration используйте REST API v1, не SSH в scheduler container. REST API designed для automation: idempotent requests, structured errors, FAB-based auth.

Что нового в 3.x (обзор)

В Airflow 3.0 REST API v2 на FastAPI с автогенерируемым OpenAPI и React-friendly contract. Также появляется airflowctl provider — remote CLI без захода в scheduler container. Обе фичи покрываются в финальном модуле upgrade path.

Закончили урок?

Отметьте его как пройденный, чтобы отслеживать свой прогресс

Войдите чтобы оценить урок

Прогресс модуля
0 из 6