re:Generate - Amazon Web Services

re:G
ene
rate
AWSマイスターシリーズ ビッグデータサービス群のおさらい + AWS Data Pipeline
2014.3.19
ソリューションアーキテクト
今井 雄太 蒋 逸峰
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
アジェンダ
!   AWSのビッグデータエコシステムのおさらい
!   AWS Data Pipelineの紹介
!   まとめ
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
AWSビッグデータサービス群のおさらい
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
AWSのビッグデータサービス群
DynamoDB
NoSQL
Data
Kinesis
Stream
Computing
EMR
Hadoop
Redshift
Data Warehouse
Data Pipeline
Workflow
Management
S3
Storage
Glacier
Cold Storage
RDS
Relational Database
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
AWSビッグデータサービス群
Amazon Simple Storage Service(S3)
•  容量量制限がなく、利利⽤用分だけの⽀支払い
で利利⽤用できるストレージ
•  データの耐久性は99.999999999%
•  静的HTTPサーバーとしても利利⽤用可
Amazon Glacier(Glacier)
•  S3と同等のデータ耐久性
•  S3の約8分の1の価格で利利⽤用可能なスト
レージ
•  データの取り出しリクエストからアクセ
ス可能になるまで約4時間かかる
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
AWSビッグデータサービス群
Amazon DynamoDB(DynamoDB)
•  NoSQL as a Service
•  ストレージ容量量の制限なし
•  必要なスループットをプロビジョンして利利⽤用
Amazon Redshift(Redshift)
•  マネージドData Ware House
•  EC2やRDSと同じように使った分だけの課⾦金金
•  スケールアウト/インも容易易
Amazon RDS(RDS)
•  マネージドRelational Database
•  PostgreSQL,MySQL,Oracle,SQL Serverか
らエンジンを選択可能
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
AWSビッグデータサービス群
Amazon Elastic MapReduce(EMR)
•  マネージドHadoop
•  HDFSとシームレスにS3を扱える
Amazon Kinesis(Kinesis)
•  Stream Computingのためのサービス
•  ストリーミングMapReduceのようなこと
を容易易に可能にしてくれる
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
AWSビッグデータサービス群
AWS Data Pipeline(Data Pipeline)
•  データの移動やETLのバッチ処理理/
パイプライン処理理のためのオーケ
ストレーションサービス
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
中⼼心にあるのはいつもS3
コンテンツ
配信
CloudFront
データ
分析
Elastic Redshift
MapReduce
コンテンツ
トランスコード
Elastic
Transcoder
データ
交換
データ
バックアップ
Amazon S3
EC2
Data Pipeline
RDS
データ
アクセスGW
EBS
Redshift
Storage
Gateway
コンテンツ
アーカイブ
Storage
Gateway
Glacier
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied,
modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
解析もオリジンデータはS3に
S3
EMR
DynamoDB
Redshift
データがS3にあれば
あとは必要に応じて解析クラスタを起動して利利⽤用できる
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
負荷
S3とEMR
キャパシティ
時間
Hadoop単体ではデータ共有はできない
↓
ひとつのデータに対する処理理は
ひとつのクラスタに強く結合してしまう
↓
キャパシティプランニングが難しい
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
負荷
S3とEMR
キャパシティ
データをHDFSではなく
S3に格納しておけば・・
時間
S3
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
負荷
S3とEMR
キャパシティ
時間
S3上のデータを複数の
クラスタから共⽤用できる
↓
仕事量量に合わせて都度度
クラスタを⽴立立ち上げて使える!
S3
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3とRedshift
COPY table_name FROM ‘s3://hoge’
CREDENTIALS ‘access_key_id:hoge…’
DELIMITER ‘,’
S3
Redshift
データ
Redshiftへのデータロードは
S3経由が効率率率的
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3とRedshift
UNLOAD (‘SELECT * FROM…’)
TO ‘s3://fuga/….’
CREDENTIALS ‘access_key_id:hoge…’;
S3
Redshift
RedshiftからS3への
エクスポートも容易易
Glacier
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3とRedshift
S3
Redshift
古いデータはより安価な
ストレージのGlacierへ
Glacier
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3とRedshift
S3
Glacier
Redshift
クラスタに問題が起こったら、
S3からクラスタを再構築
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3とDynamoDB
DynamoDB
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3とDynamoDB
古いデータはS3へオフロード
もしくはバックアップ
S3
DynamoDB
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3とDynamoDB
更更に古いデータはGlacierへ
Glacier
S3
DynamoDB
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3を使ったパイプライン処理
S3
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3を使ったパイプライン処理
EMR
S3
S3
処理理1
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3を使ったパイプライン処理
EMR
EMR
S3
S3
処理理1
S3
処理理2
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3を使ったパイプライン処理
EMR
EMR
S3
S3
処理理1
S3
処理理2
S3をチェックポイントとして利利⽤用することによって
処理理を疎結合にできる
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3を使ったパイプライン処理
EMR
EMR
S3
S3
処理理1
S3
処理理2
処理理が途中で失敗したら・・・
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
S3を使ったパイプライン処理
EMR
EMR
S3
S3
処理理1
S3
処理理2
チェックポイントからやりなおせる
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
⼤大事なことなのでもう⼀一度度。
中⼼心にあるのはいつもS3
コンテンツ
配信
CloudFront
データ
分析
Elastic Redshift
MapReduce
コンテンツ
トランスコード
Elastic
Transcoder
データ
交換
データ
バックアップ
Amazon S3
EC2
Data Pipeline
RDS
データ
アクセスGW
EBS
Redshift
Storage
Gateway
コンテンツ
アーカイブ
Storage
Gateway
Glacier
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied,
modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
ユースケース1:アクセスログレポート
USER
PATH
TIMESTAMP
-----------------------------------
USER1 /login
2014-02-26 00:00:01
USER1 /home
2014-02-26 01:12:26
USER2 /home
2014-02-26 01:13:31
1.1.1.1, /login, 20140226000101, …
1.1.1.1, /home, 20140226011226, …
1.1.1.2, /home, 20140226011331, …
Webサーバー
S3
ログ(オリジナル)
ログ集約サーバー
EMR
S3
処理済みデータ
Redshift
ETL済みデータ
ETLもしくは集計
RDS
集計済みデータ
Glacier
ログ(長期保存)
DATE
PATH
UU
------------------------
2014-02-26 /login
1
2014-02-26 /home
2
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
ユースケース2:ストリーム処理理
Kinesis
DynamoDB
Twitter
ストリームAPI
データ収集サーバー
Kinesisアプリケーション
HASH_TAG TIME
COUNT
------------------------
A
2014-02-26 00:00 30
A
2014-02-26 00:01 20
B
2014-02-26 00:00 10
B
2014-02-26 00:01 5
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
中まとめ
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
中まとめ:AWSビッグデータサービス群の俯瞰図
WebApp
DynamoDB
Kinesis
Data
BI
S3
RedShift
EMR
Dashboard
RDS
Glacier
Data Pipeline
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
WebApp
DynamoDB
Kinesis
BI
AWS Data Pipelineの紹介
Data
S3
RedShift
EMR
Dashboard
RDS
Glacier
Data Pipeline
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
なぜData Pipeline?
データのマイグレーションが簡単じゃない
•  異異なる場所、異異なるフォーマット
• 
• 
S3, RDS, EMR, Redshift, DynamoDB
オンプレミス
依存管理理が複雑
•  ⼊入⼒力力データが存在
•  前の処理理が成功
異異常処理理が必要
•  失敗時のリトライ
•  タイムアウト
•  イベント通知
Input Data
Ready?
Yes
Run…
No
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
AWS Data Pipelineとは
特定の間隔でコンピュートとストレージのサービス間
のデータ統合・処理理を⾃自動的に⾏行行うサービス
•  AWSサービス間データ連携が簡単に
•  オンプレミスとAWSの間も可能
•  ⾼高い信頼性を保つための仕組み
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
Pipelineの定義
データ処理理を定義するための情報
• 
• 
• 
• 
• 
• 
Data Node: データの場所、フォーマット
Activity: データ処理理のアクティビティ
Schedule: 処理理実⾏行行のスケジュール
Resource: 処理理や条件チェックを⾏行行うリソース
Precondition: 処理理実⾏行行の条件
Action: 通知を送る⽅方法
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
アクティビティ(Activities)
データ移動や処理理の全体を管理理
•  ⼊入出⼒力力、スケジュール、処理理内容、リソース、通知アクション
•  AWSとオンプレミスにて実⾏行行可能
サポートするアクティビティ⼀一覧
• 
• 
• 
• 
• 
• 
• 
• 
CopyActivity
EmrActivity
HiveActivity
HiveCopyActivity
PigActivity
RedshiftCopyActivity
SqlActivity
ShellCommandActivity
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
データノード
Input / Outputデータの場所やタイプを定義
•  S3パス
•  SQL データベース
•  DynamoDB
•  Redshift
フォーマット指定は⾃自由
•  CSV Data Format
•  カスタマイズ
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
データとテーブルのステージング
データにアクセスしやすいための仕組み
•  データを⾃自動的にリソースにコピー / テーブルを⾃自動的に作成
• 
データがリソースのローカルにあるように
•  サポートデータノード: S3DataNode, SqlDataNode
•  サポートアクティビティ
• 
• 
{
ShellCommandActivity
• 
• 
初期値: off. Stage = true にセット
変数: ${INPUTx_̲STAGING_̲DIR} , ${OUTPUTx_̲STAGING_̲DIR}
• 
• 
初期値: on.
変数: ${inputx}, ${outputx}
HiveActivity
Table作成は
不要
"id": "MyHiveActivity",
…
"hiveScript": "INSERT OVERWRITE TABLE ${output1} select * from ${input1};"
},
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
依存関係(Preconditions)
条件が成⽴立立した場合のみ後継タスクを実⾏行行
•  DynamoDB tableが存在/データがある
•  S3キーが存在
•  S3プリフィックスが存在
•  独⾃自のShellコマンド実⾏行行が成功
•  依存するpipelineタスクが成功
Yes
S3 key
exists?
Copy…
No
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
スケジュール
処理理を実⾏行行するタイミング
•  Cronスタイル: 指定した間隔のstart時点で起動
•  Time Seriesスタイル: 指定した間隔のend時点で起動
• 
ただし、EC2やEMRリソースは常にstart時点に作成
•  間隔: 15分、時、⽇日、週など
• 
15min ~∼ 3year
TS1 /
Cron2
Start/
Cron1
Period
TS2 /
Cron3
Period
時間
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
スケジュール(2)
Backfillタスク
•  開始時間に過去を指定した場合、現在まで遡ってタスクを繰り返
し実⾏行行
• 
テストに便便利利
•  開始時間が1⽇日以前の場合、タスク起動しない
• 
CLIで --force 引数を指定して起動可能
タイムゾン
•  初期値: UTC, “YYYY-‐‑‒MM-‐‑‒DDTHH:MM:SS” フォーマット
•  変数にタイムゾン指定可能
• 
#{inTimeZone(myDateTime,ʼ’Asia/Tokyo')}
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
リソース
タスクを実⾏行行するリソース
•  EC2: EC2-‐‑‒ClassicとEC2-‐‑‒VPC両⽅方サポート
•  EMR: タスクノードにspot instance利利⽤用可能
•  Multi-‐‑‒regionのリソース管理理が可能
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
リソース(2)
アクティビティとリソースのスケジュールを別々に指定
可能
•  リソースを最⼤大限に利利⽤用
• 
• 
• 
Activityスケジュール: 20分
Resourceスケジュール: 1時間
結果: EMRが1クラスタのみ課⾦金金
節約分
Task 1
Task 2
Task 3
時間
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
イベントと異常管理
イベントが発⽣生するタイミング
•  成功時
Task 1
•  失敗時
•  遅れが発⽣生した場合
Alert
成功
失敗
設定可能なアクション
•  SNS通知
•  リソースを削除
失敗時⾃自動リトライ
•  初回実⾏行行含め、1~∼6回の実⾏行行回数を設定可能
•  初期値は3回
Task 2
成功
Alert
失敗
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
簡単に利用スタート
• 
• 
• 
• 
よくあるユースケースはテンプレートが⽤用意
管理理画⾯面からGUI操作
CSV/TSVのネイティブサポート
⾃自動的にEMR/EC2をセットアップ
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
ファイル出力
GUIの操作結果をJSONに出⼒力力可能
•  Pipelineのバージョン管理理
•  出⼒力力したファイルは
CLIでインポート可能
./datapipeline --create pipeline_name --put pipeline_file
--activate --force
•  インポート前にバリデーションで
きる
./datapipeline –validate my-pipeline.json –credential
credetials.json --force --id df-0123456789ABCD
{
"objects": [
{
"id": "ActivityId_YYbJV",
"schedule": {
"ref": "ScheduleId_X8kbH"
},
"scriptUri": "s3://mybucket/
myscript.sh",
"name": "ShellActivity1",
"runsOn": {
"ref": "ResourceId_5nJIh"
},
...
]
}
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
料金
•  無料料使⽤用枠あり
•  アクティビティ、または依存関係の従量量課⾦金金
•  実際に利利⽤用したリソース(EC2, S3など)の課⾦金金
高頻度 (>1日1回)
低頻度
On AWS
$1.00
$0.60
オンプレミス
$2.50
$1.50
実行しないpipeline $1.00
* 2014/3/19時点、東京リージョンのアクティビティ / 依存関係の⽉月額単価
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
DynamoDB Import/Export
DynamoDB Import/ExportはData Pipelineを利利⽤用
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
Ad インプレッション集計の例
•  S3にあるログとRDSのマスタ
データを結合
•  EMR Hiveで整形
•  結果をS3に出⼒力力
•  Redshiftにロード
•  SQLで集計しBIテーブルに
ロード
•  スケジュールで起動(例例:1
回/時)
•  S3ログが存在の場合のみHive
起動
•  失敗時SNSで通知
•  リトライ設定
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
まとめ
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
AWS上のビッグデータ活用
•  AWSには多様なビッグデータ関連サービスがある
•  ユースケース別によくある構成やベストプラクティス
が存在する
•  Data Pipelineは⾼高い拡張性のある⼿手法で クラウドや
オンプレミスに蓄積されたデータを変換・処理理するこ
とできる
•  AWSのビッグデータサービスをうまく活⽤用してビッグ
データの活⽤用を加速させよう
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.
ご参加ありがとう
ございました
© 2012 Amazon.com, Inc. and its affiliates. All rights reserved. May not be copied, modified or distributed in whole or in part without the express consent of Amazon.com, Inc.