74
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 1 アマゾン ウェブ サービス ジャパン株式会社 ソリューションアーキテクト 下佐粉 2017.10.18 【AWS Black Belt Online Seminar】 AWS Glue

AWS Black Belt - AWS Glue

Embed Size (px)

Citation preview

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

1

アマゾン ウェブ サービス ジャパン株式会社

ソリューションアーキテクト 下佐粉 昭

2017.10.18

【AWS Black Belt Online Seminar】AWS Glue

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

2

自己紹介

下佐粉 昭(しもさこ あきら)

Twitter - @simosako

所属:

アマゾン ウェブ サービス ジャパン

技術統括本部 エンタープライズソリューション部

ソリューションアーキテクト

好きなAWSサービス:Redshift, RDS, S3

人間が運用等から解放されて楽になるサービスが好きです

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

3

AWS Black Belt Online Seminar へようこそ!

質問を投げることができます!Adobe ConnectのQ&Aウィンドウから、質問を書き込んでください。(書き込んだ質問は、主催者にしか見えません)

今後のロードマップに関するご質問はお答えできませんのでご了承ください。

Twitterへツイートする際はハッシュタグ #awsblackbelt をご利用ください。

①Q&Aウィンドウ右下のフォームに質問を書き込んで

ください

②吹き出しマークで送信してください

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

4

AWS Black Belt Online Seminar とはAWSJのTechメンバがAWSに関する様々な事を紹介するオンラインセミナーです

【火曜 12:00~13:00】主にAWSのソリューションや業界カットでの使いどころなどを紹介(例:IoT、金融業界向け etc.)

【水曜 18:00~19:00】主にAWSサービスの紹介やアップデートの解説(例:EC2、RDS、Lambda etc.)

※開催曜日と時間帯は変更となる場合がございます。最新の情報は下記をご確認下さい。オンラインセミナーのスケジュール&申し込みサイト• https://aws.amazon.com/jp/about-aws/events/webinars/

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

5

内容についての注意点

• 本資料では2017年10月18日時点のサービス内容および価格についてご説明しています。最新の情報はAWS公式ウェブサイト(http://aws.amazon.com)にてご確認ください。

• 資料作成には十分注意しておりますが、資料内の価格とAWS公式ウェブサイト記載の価格に相違があった場合、AWS公式ウェブサイトの価格を優先とさせていただきます。

• 価格は税抜表記となっています。日本居住者のお客様が東京リージョンを使用する場合、別途消費税をご請求させていただきます。

• AWS does not offer binding price quotes. AWS pricing is publicly available and is subject to change in accordance with the AWS Customer Agreement available at http://aws.amazon.com/agreement/. Any pricing information included in this document is provided only as an estimate of usage charges for AWS services based on certain information that you have provided. Monthly charges will be based on your actual use of AWS services, and may vary from the estimates provided.

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

6

Agenda

• AWS Glueとは

• AWS Glueの機能• データカタログ

• ジョブオーサリング

• オーケストレーション

• 開発環境

• 落穂ひろい

• まとめ

• 補足資料

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

7

AWS Glueとは

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

8

増え続けるデータに対応するために...

①データをデータレイクに集め、多様な分析につなげる

②分析は分散処理可能なインフラの上で実現

大規模データ分析 on クラウド

収集 データレイク

(保存)

分析 可視化

データを収集し、データレイクへ格納

全期間保存共通APIでアクセス

可視化

分散処理可能な技術

分析分散処理可能な技術

AP

I

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

9

分析

分析

データレイク

AWSサービスでの実現例①データをデータレイク(S3)に集め、多様な分析につなげる

②分析は分散処理可能なインフラの上で実現(Redshift, Athena, EMR...)

③データソースからの収集やプリプロセス(前処理、ETL)は?

収集

可視化Amazon

RedshiftAnazon

QuickSight

Amazon S3

BI+EC2

プリプロセス

全データ 変形済

Amazon

Athena

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

10

AWS上のETL(Extract, Transform and Load)サービス

巨大データへのETL処理を...

「分散処理」で対応「サーバレス」で提供

AWS Glue

https://aws.amazon.com/jp/glue/

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

11

分析

分析

データレイク

AWS Glueを入れた全体構成①データをデータレイク(S3)に集め、多様な分析につなげる

②分析は分散処理可能なインフラの上で実現(Redshift, Athena, EMR...)

③プリプロセス(ETL)も分散処理で実現(AWS Glue)

収集

可視化Amazon

RedshiftAmazon

QuickSight

Amazon S3

BI+EC2

プリプロセス

全データ 変形済

Amazon

Athena

AWS

Glue

AWS

Glue

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

12

AWS Glueの機能

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

13

AWS Glue – 全体像

データソースをクロールし、メタデータを取得

メタデータはデータカタログで管理

メタデータを元にジョブを作成(PySpark)

ジョブはサーバレスな環境で実行される

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

14

データカタログ

Hiveメタストア互換のデータソース用メタデータリポジトリ

テーブル、データ型、パーティションフォーマットを推測するために

ソースをクロール

Redshift Spectrum, Athena, EMRのカタログとしても利用・連携可能

オーケストレーション

分散処理でジョブを実行

サーバレス - 利用したリソース分だけの支払い

ジョブオーサリング

ETL処理のためのPythonコード(PySpark)を生成

任意のIDEでコードを作成可能

AWS Glueの構成要素

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

15

Glueデータカタログ

データセットの発見・管理

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

16

メタストアとデータストアHive メタストア (Metastore):

• Hiveで表データそのものとは別に表の定義(メタデータ)を格納するために作成された仕組み

• 表データそのものはデータストア(HDFS, S3)に保存する

• 集中して付帯情報を管理することでコーディング側での管理負担を減らす

• Hive以外の多くのプロダクトも参照するようになり、標準的なメタデータ保存の仕組みに

Hive

Pig

Presto

表Aの定義(スキーマ)、位置、フォーマット、SerDe ...

メタストア

データストア

CSVファイル

Parquetファイル

JSONファイル

①メタデータにアクセス

②実データにアクセス

表Bの定義(スキーマ)、位置、フォーマット、SerDe ...

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

17

メタストアをGlueで提供する意味

(これまで)EMRではマスターノード上のMySQLもしくはRDSに保存

Glueではサーバレスのサービスで実現

• 運用管理自体が不要にディスク上限の管理、パッチ、可用性の確保...

• 安心して複数サービスから参照できる基盤の実現

クローラーによる自動登録でさらに管理負荷を軽減

• CREATE EXTERNAL TABLEを手動で実行不要

• 例)S3にファイルを置く=>クロール=>AthenaからSELECT実行

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

18

ETL(変換)

データレイク

データウェアハウス

データベース

Glue data

catalog

Amazon

RDS

Amazon

Redshift

Amazon S3

クロールでメタデータ収集 Glue ETL

Uses

アドホック分析

データウェアハウス

分析業務

Amazon

Athena

Redshift

Spectrum

EMR

(Hive/Spark)

Uses

Uses

Uses

データカタログでAWS上のメタデータを集中管理

クロールでメタデータ収集

クロールでメタデータ収集

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

19

表のメタデータをHiveメタストアで管理

メタデータ

• 列・プロパティ・型

• データロケーション(URI)

• 更新情報

クローラーによる自動チェックと登録

• Hiveパーティションを認識し登録を自動化

Glue データカタログ (Data catalog)

/mydata/year=2017

/month=11/...

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

20

テーブルの主要情報

テーブルのプロパティ

テーブルスキーマ

テーブルパーティション

メタデータ(定義)の例

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

21

テーブルのスキーマバージョン一覧

スキーマバージョンの比較

スキーマのバージョン管理

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

22

手動でスキーマを更新可能 –追加、削除、型の変更

スキーマの修正

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

23

クローラーが自動的にスキーマを推測

• ファイルタイプを識別し、どのような内容が含まれるのかを分類(Classifier)しスキーマ、ファイルタイプ、パーティションを抽出

• Grokフィルタでカスタマイズ可能

クローラーをスケジュール実行することで新しいデータやスキーマの変更を発見

クローラーを使わず手動での登録も可能

ログはCloudWatch Logsに出力

クローラーによるデータカタログの自動更新

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

24

IAM Role

Glue クローラー

データレイク

DWH

データベース

Amazon

RDS

Amazon

Redshift

Amazon S3

JDBC 接続

オブジェクト接続

ビルトイン Classifier

MySQL/MariaDB

PostreSQL

Aurora

Oracle

SQL Server

Redshift

Avro

Parquet & ORC

JSON & BJSONログ

(Apache, Linux, MS, Ruby, Redis, and many others)

区切り形式(comma, pipe, tab, semicolon)

圧縮フォーマット(ZIP, BZIP, GZIP, LZ4, Snappy)

クローラーとClassifier

Classifierについてはこちらも参照

http://docs.aws.amazon.com/glue/latest/dg/add-classifier.html

GrokでカスタムClassifierを作成可能

RDB

on EC2

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

25

接続の管理

JDBC(RDB)• ホスト名(URL)、ID、パスワード

• セキュリティグループでアクセスを制限

S3• S3バケットを指定

• IAMでアクセスを制限

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

26

補足:カスタムClassifier

GorkパターンでカスタムClassifierを作成可能

• Grokパターンで表記できないものについては、カスタムパターン(正規表現ベース)で対応可能

%{TIMESTAMP_ISO8601:timestamp} ¥[%{MESSAGEPREFIX:message_prefix}¥]%{CRAWLERLOGLEVEL:loglevel} : %{GREEDYDATA:message}

例)Grokパターン

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

27

ジョブオーサリング

使い慣れたツールでETLジョブのオーサリング、コード開発

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

28

ジョブを作成する

ジョブ=ETL処理を実行する単位

• PySpark(Python)で記述

• Extract(抽出)や、Load(取り込み)は抽象化されているため、主にTransform(変換)を既述する

■サンプルスクリプト集

https://github.com/awslabs/aws-glue-samples(※同じサイトにFAQもあり、こちらも必読)

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

29

• GUIでデータソース、ターゲット、列のマッピングを設定することで雛形が生成される

• CSV→Parquetのフォーマット変換だけといった処理であればPythonコード作成無しで実現

GUIでのコード雛形生成

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

30

ジョブスクリプトの基本

①初期化後、カタログ経由でソースへアクセスし、DynamicFrameを作成

②DynamicFrameを操作してデータ変換

③変換後のDynamicFrameをカタログ経由でターゲット(Sink)に出力

## 初期化処理(importやGlueContextの作成、引数処理等)glueContext = GlueContext(SparkContext.getOrCreate())

##ソースからデータを取り出すds0 = glueContext.create_dynamic_frame.from_catalog (

database = "mysql", table_name = "customer", transformation_ctx = "ds0")

##ここで変換処理を既述ds1 = ds0 ...

##ターゲット(Sink)への書き出しds2 = glueContext.write_dynamic_frame.from_catalog (frame = ds1, database = "redshift", table_name = "customer_dim", redshift_tmp_dir = args["TempDir"], transformation_ctx = "ds2")

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

31

①初期化~ソースへアクセス

• GlueContextはPySparkのSQLContextを継承してGlue独自の機能を追加したもの

• https://github.com/awslabs/aws-glue-libs/blob/master/awsglue/context.py

• GlueContextを作成し、create_dynamic_frame.from_catalogでカタログ経由で

DynamcFrameを作成する

• 補足) 1つのジョブの中で複数のデータベースにアクセスする場合、それらが同一サブネッ

トに配置されている必要がある

glueContext = GlueContext(SparkContext.getOrCreate())ds0 = glueContext.create_dynamic_frame.from_catalog(database = "flightsdb", table_name = "flightsparquet",transformation_ctx = "ds0")

※カタログを経由せず、glueContext.create_dynamic_frame.from_optionsで作成することも可能※DataFrameをDynamicFrame.fromDFで変換してDynamicFrameを作成することも可能

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

32

②データ操作DynamicFrameとDataFrame

データそのものを表すクラス• DynamicFrame : データ全体• DynamicRecord:データ1行

SparkSQLのDataFrameに似た概念• DataFrameと違い、初期化時のスキーマ定義が不要• 型が必用な時は自動で、もしくはユーザ制御で決定(Choice)

DataFrameとの互換性• fromDF/toDFメソッドでDynamicFrame⇔DataFrameの変換が可能• データ操作はDataFrameで実化し、データのIN/OUT時だけDynamicFrameを使用するというコーディングも可能

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

33

DynamicFrameとChoice

DynamicFrameの列に複数の型を発見した場合、図のようにChoice可能な状態で維持される

• 同じ列に異なる型が混じったデータセットを扱うことを可能にする

• resolveChoiceで型が一致しない部分の解決方法を指定可能

• NULLにする、削除する、型ごとに別列に分ける、Struct型で保持する

medicare_dyf = glueContext.create_dynamic_frame.from_catalog (

database = "payments",table_name = "medicare")

medicare_dyf.printSchema()

root

|-- drg definition: string

|-- provider id: choice

| |-- long

| |-- stringprovider id列はlongとstring両方のデータを持つ

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

34

ビルトインの変換クラス・メソッド

• DynamicFrameには変換のためのメソッドが用意されている(今後も追加予定)

• 管理コンソールではクリックでビルトイン変換のサンプルコードが追加される

• DataFrameに変換してSparkSQLで変換する方法も可能

ビルトイン変換の一覧:

http://docs.aws.amazon.com/ja_jp/glue/latest/dg/built-in-transforms.html

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

35

変換の例:ジョイン

ジョインはDynamicFrameの joinメソッドで提供される

datasource0 = glueContext.create_dynamic_frame.from_catalog(...)datasource1 = glueContext.create_dynamic_frame.from_catalog(...)

:#datasouce0とdatasouce1をORDER_ID列でジョインするdatasource2=datasource0.join( ["ORDER_ID"],["ORDER_ID"], datasource1)

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

36

変換の例:フィルタリング

SplitRowsクラスで条件によるDynamicFrameの分割で実現

もしくはDataFrameに変換してフィルタリング

frame_collection = SplitRows.apply(my_dynamic_frame,{"age": {">": 21}}, "adults", "youths")print frame_collection["youths"]

ret_df = my_dynamic_frame.toDF().filter("age > 21")new_dyn_f = DynamicFrame.fromDF(ret_df, glueContext,"new_dyn_f")

my_dynamic_frame.toDF().createOrReplaceTempView("temptable")sql_df = spark.sql("SELECT * FROM temptable WHERE age > 21")new_dyn_f = DynamicFrame.fromDF(sql_df, glueContext,"new_dyn_f")

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

37

③ターゲット(Sink)への書き出しターゲットの列にDynamicFrameをあわせる処理

• ApplyMapping.apply – 列マッピングの定義

• SelectFields.Apply – 出力する列を設定※これらは管理コンソールのウィザードで自動生成されるので、通常ユーザは作成しない

最後にwrite_dynamic_frame.from_catalogで出力

applymapping1 = ApplyMapping.apply(frame = datasource2, mappings = [("COUNTRY", "string", "country", "string"),*中略*

, ("NAME", "string", "name", "string")], transformation_ctx = "applymapping1")

selectfields2 = SelectFields.apply(frame = applymapping1, paths = ["mktsegment", "country", *中略* "cust_id"], transformation_ctx = "selectfields2")

datasink3 = glueContext.write_dynamic_frame.from_catalog(frame = selectfields2, database = "demo-redshift", table_name = "salesdwh_public_customer_dim", redshift_tmp_dir = args["TempDir"], transformation_ctx = "datasink3")

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

38

補足:S3への書き出し時のフォーマット

write_dybamic_frame.from_optionsを使用することで、任意のS3に対しフォーマットを指定して出力することが可能です

ds2 = glueContext.write_dynamic_frame.from_options(frame = ds1, connection_type = "s3", connection_options = {"path": "s3://demo1/output"}, format = "parquet",transformation_ctx = "ds2")

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

39

ジョブへの引数の受け渡し

• ジョブ起動時にパラメータを指定することが可能• Keyは'--'から始まるようにする(例:--Arg1)• sys.argvに入るので、それをgetResolveOptionsで読み取りやすい形にして利用する(引数名の大文字小文字を区別するので注意)

from awsglue.utils import getResolvedOptions

args = getResolvedOptions(sys.argv, ['INPUT', 'OUTPUT'])print "The value of Arg1: " , args['INPUT']print "The value of Arg2: " , args['OUTPUT']

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

40

オーケストレーション&リソース管理

フルマネージド、サーバレスのジョブ実行

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

41

ジョブの定義と実行作成したJOBスクリプトを読み込んで実行

• IAMロールで権限を設定

ジョブの実行開始方法• APIコール(手動)• トリガー

リトライ制限の指定や、パラメータを渡すことが可能

実行ログはCloudWatch Logsに出力

CloudWatch Eventでジョブ実行・失敗のイベントをフック可能(成功時に別のサービスを呼び出す等)http://docs.aws.amazon.com/ja_jp/AmazonCloudWatch/latest/events/EventTypes.html#glue-event-types

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

42

ライブラリの利用

ジョブ実行時にライブラリを指定可能• Python (2.7) ライブラリ

• S3にライブラリファイルを置いてジョブ作成時に指定する

• S3のURLは複数をカンマで設定可能• Pure Pythonコードであること(pandas等C言語拡張に依存するライブラリは利用できません)

• Java ライブラリ• 同上。S3にJarを置いて指定する• Pure JavaもしくはScala 2.11ベースのコードのみ

参照)

http://docs.aws.amazon.com/glue/latest/dg/console-custom-created.html

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

43

トリガー

トリガー:ジョブを起動するきっかけ

ジョブ開始のタイミング• 先行ジョブ完了時

• スケジュール

• API(オンデマンド)

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

44

サーバレスのジョブ実行環境

サーバ管理や準備が不要

ジョブに必要なインスタンスが自動的に用意される

ENIがVPC内に作成され、ENI経由でVPC内リソースにアクセス可能

お客様VPC お客様VPC

インスタンスプール

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

45

ジョブ実行時のVPC内へのアクセス

• ENI経由でアクセスされるため、ジョブインスタンスはVPC内に存在するように見える(※VPC内のリソースにアクセスするジョブの場合)

• ENIにはサブネット内のプライベートIPが付与されるため、インターネットへのアクセスが無いプライベートサブネットでも利用可能

• ジョブの中でプライベートサブネットからS3にアクセスする必要がある場合はVPC Endpointの設定が必須

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

46

補足:Glueとセキュリティグループ

• ジョブが参照するリソース(RDB)はGlueジョブのクラスタから参照可能なようにセ

キュリティグループを設定する必要がある

• そのため、自己参照型(自セキュリティグループからのアクセスを全て許可するルー

ル)のセキュリティグループを作成し、それをリソースとGlueジョブに設定する

参照)

http://docs.aws.amazon.com/glue/latest/dg/setup-vpc-for-glue-access.html

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

47

ETLジョブの実行状況確認

• ETLジョブの状況は管理コンソールに表示される

• ログはCloudWatch Logsに出力される

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

48

開発環境

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

49

Development Endpoint

Development Endpoint• ジョブ実行環境に直接接続するためのElasitic IPアドレス。REPLにアクセス可能

• 作成時にSSH鍵を登録するが、通常のEC2用とは別に用意することを推奨

開発用にNotebook(Zeppelin)サーバも提供• http://zeppelin.apache.org/• Endpointを選択→Actionから作成可能• CloudFormationで自動生成

補足)• Dev. Endpointを削除してもNotebookサーバは消えない• Zeppelin自体のトラブルは~/zeppelin/logsにログが出力されるのでSSHでログインして確認• スクリプト内でprintした値はCloudWatch Logs(Error logs)経由で出力される

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

50

Dev. EndpointとNotebook (Zeppelin)サーバ

補足:NotebookからDev.EndpointへはローカルポートをSSHでポートフォワードしているため、Notebook作成時にDev.Endpointのプライベートキーが必用になる

Office

Internet

virtual private cloud

Notebook(Zeppelin)Server

HTTPS for

Zeppelin

Dev.

Endpoint

AWS Glue インスタンスプール

SSH port forward

SSH for REPL

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

51

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

52

落穂ひろい

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

53

GlueとIAM Role①

ETLジョブ用• IAM Roleを作成しジョブ実行時に指定する• AWSGlueServiceRoleが定義済なので、開発用等であればこのポリシーをアタッチするのが簡単

• IAMの名前はAWSGlueServiceRoleから始まる名前にする(もしくはiam:PassRoleを含める)

• 詳細:http://docs.aws.amazon.com/ja_jp/glue/latest/dg/create-an-iam-role.html

Development endpointアクセス用:• Notebookから各種リソースにアクセスをするために必用• AWSGlueServiceNotebookRoleポリシーが定義済なので、これに加えて

AmazonS3FullAccess 等必用な権限を追加する• AWSGlueServiceNotebookRoleから始まる名前にする(もしくは

iam:PassRoleを含める)• 詳細: http://docs.aws.amazon.com/ja_jp/glue/latest/dg/create-an-iam-role-

notebook.html

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

54

GlueとIAM Role②

開発ユーザのIAM(管理コンソールログイン用)• AWS管理のAWSGlueConsoleFullAccessと、加えて

CloudWatchLogsReadOnlyAccess 、AWSCloudFormationReadOnlyAccess、AmazonAthenaFullAccessが必用

• 詳細:http://docs.aws.amazon.com/ja_jp/glue/latest/dg/attach-policy-iam-user.html

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

55

AWS Glue 料金(*)

ETLジョブ実行:

• $0.44/DPU/時(課金は秒単位)

• 10分間未満の処理は10分として計算されます

• 1 DPU = 4vCPU, 16GBメモリ

クローラー:

• $0.44/DPU/時(課金は秒単位)

• クローラーの処理能力は2DPUで計算

• 10分間未満の処理は10分として計算されます

データカタログへのストア:

• 100万オブジェクトまで無料

• それ以上は10万オブジェクトあたり$1/月

データカタログへのリクエスト:

• 100万リクエスト/月まで無料

• それ以上は100万リクエストあたりい$1/月

その他:

• S3へのアクセスに掛かる費用等は別途必要です

* 2017/10/18時点のU.S. East (N. Virginia), U.S. East (Ohio), U.S. West (Oregon)での価格です。最新の情報は以下URLを御確認ください。

https://aws.amazon.com/glue/pricing/

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

56

AWS Glue - Development Endpoint利用の費用

Development Endpoint経由の実行:

• DPU単位の費用がEndpoint作成した直後から発生(削除するまで)

• 不要な期間は削除することで費用を抑えることが可能

• DPUの数はEndpoint作成時に指定可能• デフォルトは5。最低でも2必要

Zeppelin server :

• 通常のAmazon EC2利用費用

• m4.xlarge

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

57

まとめ

AWS Glueは、サーバレスで分散処理を実現するETLサービス

データカタログとクローラーがメタデータ管理を実現

ETL処理はPySparkで実現

• コーディングによる生産性

• 既存のPySparkライブラリの活用

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

58

補足資料

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

59

Amazon EMRとAWS Glueの違い

Amazon EMR AWS Glue

用途 汎用Hadoop/Spark環境 ETL処理に特化(Sparkベース)

スケールアウト 可能(ユーザ設計) 可能(パラメータ指定)

サーバ管理 数クリックで指定した環境が準備される

サーバ管理が不要(サーバレス)

データレイク(S3)への透過的なアクセス

可能 可能

プログラミング環境 Hadoopエコシステム上の多様なアプリケーション

PySparkでETL処理を作成

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

60

FAQ

[Q] クローラーからデータソースにつながりません

[A] ドキュメントに沿って以下の設定を見直してください

• データソースに自己参照型のSGが設定されているか

• クローラーが必用な権限(Role)を持っているか

[Q] Glueを動かしているSparkのバージョンは?

[A] 現時点ではSpark 2.1です

[Q] クローラーが型を認識する際には全データをスキャンしているのですか?

[A] クローラーがデータ型を認識するために取得するデータは先頭2MB分のみ

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

61

FAQ

[Q] 既存HiveのMetastoreからGlueのData Catalogへ移行するには?

[A] 移行ツールを用意しています

• https://github.com/awslabs/aws-glue-samples/tree/master/utilities/Hive_metastore_migration

[Q] ETL処理に関係ないプログラムを動かせますか?

[A] Jobの中ではPySparkで自由にプログラムを記述することが可能です。現時点では言語はPySparkのみのサポートであるため、E汎用的な処理にはAmazon EMRも検討してください

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

62

FAQ

[Q] Jobプログラムの中から、Glueデータカタログが持つ接続情報を得るには?[A] 以下のサンプルを参考にしてください

glue=boto3.client(service_name='glue', region_name='us-east-1',

endpoint_url='https://glue.us-east-1.amazonaws.com')

redshiftConnection=glue.get_connection(Name=target_database)

jdbc_url=redshiftConnection['Connection']['ConnectionProperties']['JDBC_CONNECTION_URL']

username= redshiftConnection['Connection']['ConnectionProperties']['USERNAME']

password= redshiftConnection['Connection']['ConnectionProperties']['PASSWORD']

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

63

FAQ

[Q] トリガーを設定したのにジョブが実行されません[A] 以下のポイントを見直してください• トリガーのステータスが ACTIVATED になっているかどうか• トリガーを作ると CREATED となるので、"Trigger-->Actions-->Enable

Trigger" から ACTIVATED としてください。

• (トリガーのタイプが "Job completed" である場合) 最初のジョブがトリガー経由で実行されているかどうか。

• 最初のジョブが手動で実行された場合、"Job completed" のトリガーに関連付けられた後続のジョブは実行されません。これは各ジョブを個別にテスト可能とするための仕様です。

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

64

参考資料

AWS Glue ホームページ• https://aws.amazon.com/jp/glue/

AWS Glue 開発者ガイド(公式ドキュメント)• https://aws.amazon.com/jp/documentation/glue/

AWS Glue ETL Code Samples (サンプルコード)• https://github.com/awslabs/aws-glue-samples

AWS Glue用のPythonパッケージ(awsglue.*のソースコード)• https://github.com/awslabs/aws-glue-libs/tree/master/awsglue

AWS Glue Data CatalogとHive Metastoreとの変換• https://github.com/awslabs/aws-glue-

samples/tree/master/utilities/Hive_metastore_migration

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

65

参考資料

Redshift Data Source for Apache Spark

• RedshiftのデータをDataFrameで操作するためのライブラリ

• https://github.com/databricks/spark-redshift

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

66

Q&A

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

67

オンラインセミナー資料の配置場所

AWS クラウドサービス活用資料集• http://aws.amazon.com/jp/aws-jp-introduction/

AWS Solutions Architect ブログ• 最新の情報、セミナー中のQ&A等が掲載されています• http://aws.typepad.com/sajp/

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

68

公式Twitter/FacebookAWSの最新情報をお届けします

@awscloud_jp

検索

最新技術情報、イベント情報、お役立ち情報、お得なキャンペーン情報などを日々更新しています!

もしくはhttp://on.fb.me/1vR8yWm

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

69

AWSの導入、お問い合わせのご相談

AWSクラウド導入に関するご質問、お見積り、資料請求をご希望のお客様は以下のリンクよりお気軽にご相談くださいhttps://aws.amazon.com/jp/contact-us/aws-sales/

※「AWS 問い合わせ」で検索してください

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

70

AWS Black Belt Online Seminar10月の配信予定

• 10月3日(火) 12:00~13:00 AWSへのネットワーク接続とAWS上のネットワーク内部設計

• 10月4日(水) 18:00~19:00 Amazon GameLift• 10月10日(火) 12:00~13:00 AWSにおけるアプリ認証パターンのご紹介

• 10月11日(水) 18:00~19:00 Amazon Kinesis• 10月18日(水) 18:00~19:00 AWS Glue• 10月24日(火) 12:00~13:00 エグゼクティブ向け

AWS紹介• 10月25日(水) 18:00~19:00 AWS Key

Management Service

申し込みサイト• https://aws.amazon.com/jp/about-aws/events/webinars/• (もしくは「AWS セミナー」で検索)

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

71

AWS Black Belt Online Seminar11月の配信予定 (+ 一部先行予告)

• 11月1日(水) 18:00~19:00 Amazon EMR

• 11月9日(木) 12:00~13:00 Amazon Pinpoint で始めるモバイルアプリのグロースハック

• 11月15日(水) 18:00~19:00 ELB Update -Network Load Balancer(NLB)と関連サービス

• 11月21日(火) 12:00~13:00 AWS上の位置情報

• 11月22日(水) 18:00~19:00 AWS WAF

• 12月1日(金) 12:00~13:00 AWS re:Invent2017 Report

申し込みサイト• https://aws.amazon.com/jp/about-aws/events/webinars/• (もしくは「AWS セミナー」で検索)

※下線はイレギュラー日程です。ご注意ください

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

72

簡単なアンケートにご協力ください

画面に表示されるアンケートフォームに入力をお願いします。皆様のご意見は、今後の改善活動に活用させて頂きます。

コメント欄には1行で自由な内容を書き込み下さい。

例)

- 本オンラインセミナーへのご意見

- 今後オンラインセミナーで取り上げて欲しい題材

- 発表者への激励

等々…

※Q&A同様に書き込んだ内容は主催者にしか見えません

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

73

ご参加ありがとうございました

© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.

74