절차.
- 시트 API를 활성화하고 구글 서비스 어카운트를 생성한 후 해당 내용을 JSON 파일로 다운로드.
- 어카운트에서 생성해 준 이메일을 조작하고 싶은 시트에 공유.
- Airflow DAG 쪽에서 해당 JSON 파일로 인증하고 앞서 시트를 조작.
알아볼 내용.
- Airflow의 건강 여부 체크(health check).
- Airflow API로 외부에서 Airflow 조작하는 방법.
auth_backend = airflow.api.auth.backend.basic_auth
docker-compose.yaml에는 이미 설정되어 있음. (AIRFLOWAPIAUTH_BACKENDS. AIRFLOW섹션키)
docker exec -it learn-airflow-airflow-scheduler-1 airflow config get-value api auth_backend
명령어로 확인.
Airflow Web UI에서 새로운 사용자 추가. (Security -> List Users)
curl -X GET --user "monitor:MonitorUser1" http://localhost:8080/health
API 사용 예.
- https://airflow.apache.org/docs/apache-airflow/stable/stable-rest-api-ref.html#section/Overview
- 특정 DAG를 API로 트리거하기.
curl -X POST "airflow:airflow" -H ... -d '' "http://localhost:8080/api/v1/dags/DAG 아이디/dagRuns"
- 모든 DAG 리스트하기.
curl -X GET --user "airflow:airflow" http://localhost:8080/api/v1/dags
- 모든 Variable 리스트하기.
curl -X GET --user "airflow:airflow" http://localhost:8080/api/v1/variables
- 모든 Config 리스트하기.
curl -X GET --user "airflow:airflow" http://localhost:8080/api/v1/config
기본적으로 Disabled로 돼 있기에 확인할 수가 없음. 따라서, airflow.cfg에서 해당 섹션을 찾아 키 값을 변경해 주어야 함.
혹은 airflow {variables, connections} {export, import} {variables, connections}.json
등으로 (Web UI에서 처럼) 확인 가능.
docker exec -it learn-airflow-airflow-scheduler-1 airflow config get-value api auth_backend
로 api 확인.
curl -X POST --user "airflow:airflow" -H 'Content-Type: application/json' -d '{"execution_date": "2023-05-24T00:00:00Z"}' "http://localhost:8080/api/v1/dags/HelloWorld/dagRuns"
처럼 특정 dag에 대해 api로 호출 가능.