Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Airflowのチュートリアルやってみた
Search
iwamot
June 30, 2023
Technology
0
240
Airflowのチュートリアルやってみた
2023-06-30
ENECHANGE Tech Talk(社内勉強会)
iwamot
June 30, 2023
Tweet
Share
More Decks by iwamot
See All by iwamot
DockerのマルチプラットフォームイメージをGitHub Actionsでビルドして公開する際に、参考にしたドキュメントと便利だったツール
iwamot
3
120
RAGもファインチューニングも使わない 素朴なAIチャットボットを職場に導入した結果
iwamot
0
70
Amazon CloudWatchでSLOを監視してみた CODT 2024 クロージングイベント版
iwamot
0
63
Cost-Effective SLO Error Budget Monitoring with Athena and CloudWatch
iwamot
0
810
Amazon CloudWatchでSLOを監視してみた
iwamot
0
39
AWS Protonの概要
iwamot
0
110
ENECHANGEが実現した管理者の工数負担を削減しながらもAWSセキュリティを強化した方法とは
iwamot
0
140
Web APIのAWS Lambda移行で工夫したこと
iwamot
4
3.2k
ECS on FargateへのSeekable OCI導入レポート
iwamot
0
500
Other Decks in Technology
See All in Technology
Valuable Software Engineering
avandeursen
0
240
エンジニアは伝え方が9割/90% of what engineers need is communication skills
ykanoh
2
140
Understanding and Optimising INP
akshayysharma
0
150
Report of JAWS PANKRATION 2024, a global online event using Amazon IVS
yoshimi0227
1
130
エムスリーマネジメントチーム紹介資料 / Introduction of M3 Management Team
m3_engineering
0
240
低コストで実現する社内文書RAG機能を搭載したAIチャットボット開発
takapy
3
530
第45回 MLOps 勉強会 - ML Test Score を用いた機械学習システムの定量的なアセスメント
masatakashiwagi
2
110
AI時代のアジャイル開発(XP祭り2024版) / Agile Development in the AI Era in XPJUG
takaking22
13
3.3k
オープニング / MIERUNE JCT - Tokyo 2024
mierune
PRO
1
330
【ログ分析勉強会#5】Elasticsearch/Kibana のパイプ型クエリー言語ES|QLの紹介 ~ Pandasと一緒にログ分析してみた
nobuhikosekiya
0
160
無料版Copilot×Google ColabでPDFデータを分析してみよう!!
kudou55
1
160
VS CodeでF1〜12キーつかってますか? / Do you use the F1-12 keys in VS Code?
74th
1
210
Featured
See All Featured
Ruby is Unlike a Banana
tanoku
96
11k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
225
22k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
3
77
Designing for Performance
lara
604
68k
What's new in Ruby 2.0
geeforr
340
31k
5 minutes of I Can Smell Your CMS
philhawksworth
202
19k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
26
4k
ParisWeb 2013: Learning to Love: Crash Course in Emotional UX Design
dotmariusz
109
6.9k
RailsConf 2023
tenderlove
28
830
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9k
Agile that works and the tools we love
rasmusluckow
327
21k
Pencils Down: Stop Designing & Start Developing
hursman
119
11k
Transcript
Airflowのチュートリアルやってみた 2023-06-30 ENECHANGE Tech Talk(社内勉強会) CTO室 岩本隆史
Airflow案件に関わることに
よい機会なのでMWAAを試したい https://aws.amazon.com/jp/managed-workflows-for-apache-airflow/
チュートリアルをやってみよう https://docs.aws.amazon.com/mwaa/latest/userguide/quick-start.html
めっちゃ時間かかった… https://docs.aws.amazon.com/mwaa/latest/userguide/quick-start.html#quick-start- createstack
Dockerだと数分で構築完了 curl -LfO 'https://airflow.apache.org/docs/apache-airflow/2.6.2/docker-compose.yaml' mkdir -p ./dags ./logs ./plugins ./config
echo -e "AIRFLOW_UID=$(id -u)" > .env docker compose up airflow-init docker compose up https://airflow.apache.org/docs/apache-airflow/stable/howto/docker-compose/
サンプルDAGも豊富
tutorial DAGを実行
成功
3つのタスク
タスク1=日付の出力 t1 = BashOperator( task_id="print_date", bash_command="date", ) [2023-06-22, 06:52:22 UTC]
{subprocess.py:75} INFO - Running command: ['/bin/bash', '-c', 'date'] [2023-06-22, 06:52:22 UTC] {subprocess.py:86} INFO - Output: [2023-06-22, 06:52:22 UTC] {subprocess.py:93} INFO - Thu Jun 22 06:52:22 UTC 2023 [2023-06-22, 06:52:22 UTC] {subprocess.py:97} INFO - Command exited with return code 0
タスク2=スリープ t2 = BashOperator( task_id="sleep", depends_on_past=False, bash_command="sleep 5", retries=3, )
[2023-06-22, 06:52:25 UTC] {subprocess.py:75} INFO - Running command: ['/bin/bash', '-c', 'sleep 5'] [2023-06-22, 06:52:25 UTC] {subprocess.py:86} INFO - Output: [2023-06-22, 06:52:30 UTC] {subprocess.py:97} INFO - Command exited with return code 0
タスク3=テンプレートの利用 templated_command = dedent( """ {% for i in range(5)
%} echo "{{ ds }}" echo "{{ macros.ds_add(ds, 7)}}" {% endfor %} """ ) t3 = BashOperator( task_id="templated", depends_on_past=False, bash_command=templated_command, )
10個のechoにレンダリング echo "2023-06-22" echo "2023-06-29" echo "2023-06-22" echo "2023-06-29" echo
"2023-06-22" echo "2023-06-29" echo "2023-06-22" echo "2023-06-29" echo "2023-06-22" echo "2023-06-29"
10個の日付が出力 [2023-06-22, 06:52:25 UTC] {subprocess.py:86} INFO - Output: [2023-06-22, 06:52:25
UTC] {subprocess.py:93} INFO - 2023-06-22 [2023-06-22, 06:52:25 UTC] {subprocess.py:93} INFO - 2023-06-29 [2023-06-22, 06:52:25 UTC] {subprocess.py:93} INFO - 2023-06-22 [2023-06-22, 06:52:25 UTC] {subprocess.py:93} INFO - 2023-06-29 [2023-06-22, 06:52:25 UTC] {subprocess.py:93} INFO - 2023-06-22 [2023-06-22, 06:52:25 UTC] {subprocess.py:93} INFO - 2023-06-29 [2023-06-22, 06:52:25 UTC] {subprocess.py:93} INFO - 2023-06-22 [2023-06-22, 06:52:25 UTC] {subprocess.py:93} INFO - 2023-06-29 [2023-06-22, 06:52:25 UTC] {subprocess.py:93} INFO - 2023-06-22 [2023-06-22, 06:52:25 UTC] {subprocess.py:93} INFO - 2023-06-29 [2023-06-22, 06:52:25 UTC] {subprocess.py:97} INFO - Command exited with return code 0
タスク依存関係は演算子で指定 t1 >> [t2, t3]
別のチュートリアルも実行
Extract @task() def extract(): data_string = '{"1001": 301.27, "1002": 433.21,
"1003": 502.22}' order_data_dict = json.loads(data_string) return order_data_dict Key Value return_value {'1001': 301.27, '1002': 433.21, '1003': 502.22}
Transform @task(multiple_outputs=True) def transform(order_data_dict: dict): total_order_value = 0 for value
in order_data_dict.values(): total_order_value += value return {"total_order_value": total_order_value} Key Value total_order_value 1236.7 return_value {'total_order_value': 1236.7}
Load @task() def load(total_order_value: float): print(f"Total order value is: {total_order_value:.2f}")
[2023-06-22, 07:55:00 UTC] {logging_mixin.py:149} INFO - Total order value is: 1236.70
タスク依存関係は自動解決 order_data = extract() order_summary = transform(order_data) load(order_summary["total_order_value"])
実はAirflow 2.0の新機能 @task def hello_name(name: str): print(f'Hello {name}!') hello_name('Airflow users')
Dockerで気軽に試そう