概要
ConnectionやVariableの値はWeb UIから入れられるけど、実運用ではコマンドラインから構築できるようになっていた方が便利。
試しにConnectionとVariableにそれぞれ値を投入してみる。
バージョン情報
- Python 3.6.7
- apache-airflow==1.10.3
Connections
Connectionの一覧を取得。
$ airflow connections --list
上記で出力されたdefaultの設定を元に書き換えていけばわかりやすい。
試しにhttpのConnectionを1つ作成してみる。http_default の値を参考にしながら埋める。
$ airflow connections --add \ --conn_id http_imind \ --conn_type http \ --conn_host https://blog.imind.jp/ \
再度一覧表示を実行すると、リストの末尾に下記のように値が登録されている
'http_imind' │ 'http' │ 'https://blog.imind.jp/' |
続いてPostgreSQLのconnectionを追加してみる。こちらもpostgres_defaultに参考に。
$ airflow connections \ --add \ --conn_id postgres_example \ --conn_type postrges \ --conn_host host_name \ --conn_schema database_name \ --conn_login user_name \ --conn_port 5432
Variables
続いてVariableの登録。
Key=foo, Val=barで登録してみる。
$ airflow variables --set foo bar
登録できたか確認。
$ airflow variables --get foo bar
登録したキーを削除。
$ airflow variables --delete foo
VariableをJSONで登録
VariableはJSONで持っておいて登録することもできる。
{ "slack_api_token": "your api token", "ssh_password": "your ssh password" }
--importを指定して上記のファイルのパスを指定して実行。
$ airflow variables --import variables.json 2 of 2 variables successfully updated.
改定履歴
Author: Masato Watanabe, Date: 2019-04-22 記事投稿