30
個個個個 個個個個個 Step Functions 個 個個個個個個個個個 States Language っっっっclassmethod.jp 1 2016 っ 12 っ 6 っ っっ っ

20161206 re growth-tokyo-maroon1st

  • Upload
    -

  • View
    626

  • Download
    0

Embed Size (px)

Citation preview

Page 1: 20161206 re growth-tokyo-maroon1st

個人的に一番ササッたStep Functions を軽くだけ触ってみた

States Language って何物?

classmethod.jp 1

2016 年 12 月 6 日 大栗 宗

Page 2: 20161206 re growth-tokyo-maroon1st

お前誰よ?

• 大栗 宗( @maroon1st )

• re:Invent は入社してからずっと参加3 回連続で合計 3 回

• ブログ以外の仕事は AWS の導入支援など

• 好きなサービスRDS/SSM/CloudFormationStep Functions ← New!

• シガー検定 ( はじめての葉巻検定 )AWS エキスパート養成読本

classmethod.jp 2

Page 3: 20161206 re growth-tokyo-maroon1st

classmethod.jp 3

re:Invent 期間中に開催された

AWS ウルトラクイズで優勝しました!

Page 4: 20161206 re growth-tokyo-maroon1st

classmethod.jp 4

Page 5: 20161206 re growth-tokyo-maroon1st

classmethod.jp 5

でも Japan Tour の中

Page 6: 20161206 re growth-tokyo-maroon1st

classmethod.jp 6

いづれは世界デビュー

Page 7: 20161206 re growth-tokyo-maroon1st

アジェンダ

• Step Functions とは?

• 何ができるの?

• Amazon States Language• ちょっとしたデモ

• まとめ

classmethod.jp 7

Page 8: 20161206 re growth-tokyo-maroon1st

STEP FUNCTIONS とは?

classmethod.jp 8

Page 9: 20161206 re growth-tokyo-maroon1st

Step Functionsビジュアルなワークフローにて、アプリケーションのコンポーネントを一連のステップとしてコーディネートすることが出来ます。→ つまり Lambda などを色々つなげて、いい感じに連携できて、大きな処理をワークフローとしてビジュアル化、実行できるサービス。

classmethod.jp 9

Page 10: 20161206 re growth-tokyo-maroon1st

Step Functions

classmethod.jp 10

Page 11: 20161206 re growth-tokyo-maroon1st

Step Functions

classmethod.jp 11

Page 12: 20161206 re growth-tokyo-maroon1st

Step Functions

ちなみに Lambda 以外も動きます。Q: How does AWS Step Functions work with other AWS services?AWS Step Functions works in conjunction with several other AWS services – including AWS Lambda, Amazon EC2, Amazon EC2 Container Service (ECS), Amazon CloudWatch, and Auto Scaling.Tasks can be implemented using Lambda functions, or using programs running on EC2 or in ECS containers.

classmethod.jp 12

Page 13: 20161206 re growth-tokyo-maroon1st

何ができるの?

classmethod.jp 13

Page 14: 20161206 re growth-tokyo-maroon1st

ステートマシン

入力条件と現在の状態によって次の状態が決まる順序回路をステート・マシンと呼びます。状態遷移図でモデル化します。手順に従って制御を行う場合などによく使用します。

classmethod.jp 14

Page 15: 20161206 re growth-tokyo-maroon1st

Lambda 連携

今までは Lambda で大きな処理を行う場合には、 Lambda から Lambda を呼ぶ必要があった。

Lambda Functions 同士が密結合してメンテナンス性が低かったが Step Functions により依存を外部で記述できるようになり疎結合に記述できる。

classmethod.jp 15

Page 16: 20161206 re growth-tokyo-maroon1st

バッチジョブのフロー定義

EC2 や ECS の処理を Activity として定義して連携ができる。いわゆるジョブフローも定義可能。正直 AWS Batch との住み分けが。。。

classmethod.jp 16

Page 17: 20161206 re growth-tokyo-maroon1st

AMAZONSTATES LANGUAGE

classmethod.jp 17

Page 18: 20161206 re growth-tokyo-maroon1st

Amazon States Language{ "Comment": "A Catch example of the Amazon States Language", "StartAt": "HelloWorld", "TimeoutSeconds": "1200", "Version": "1.0", "States": { "HelloWorld": { "Type": "Task", "Resource": "arn:aws:lambda:REGION:ACCOUNT_ID:function:FUNCTION_NAME", "Catch": [… ], "End": true }, "CustomErrorFallback": {… } }}

classmethod.jp 18

Page 19: 20161206 re growth-tokyo-maroon1st

Amazon States Language• States– ワークフロー全体

• 以下がある– Task– Wait– Pass– Succeed– Fail– Choice– Parallel

classmethod.jp 19

Page 20: 20161206 re growth-tokyo-maroon1st

Amazon States LanguageStates• Task–任意のコードで記述するアクティビティ–主に Lambda を使用– EC2 や ECS も実行できる

classmethod.jp 20

Page 21: 20161206 re growth-tokyo-maroon1st

Amazon States LanguageStates• Wait–指定された時間待つ–期間を秒数で指定したり時刻を指定

• Pass–何もしない–入力をそのまま出力する

classmethod.jp 21

Page 22: 20161206 re growth-tokyo-maroon1st

Amazon States LanguageStates• Succeed– 正常に停止する

• Fail– 異常終了する

• Choice– 条件により処理を分岐させる

• Parallel– 処理を並列に実行する

classmethod.jp 22

Page 23: 20161206 re growth-tokyo-maroon1st

Amazon States LanguagePaths• 入出力で使用する JSON データの指定

classmethod.jp 23

Path Value

$.foo 123

$.bar ["a", "b", "c"]

$.car.cdr true

Page 24: 20161206 re growth-tokyo-maroon1st

Amazon States LanguageErrors実行時のエラーを定義する• States.ALL

– 全てのエラーに一致• States.Timeout

– タスクのタイムアウト• States.TaskFailed

– Task の実行エラー• States.Permissions

– 権限不足によるエラー

classmethod.jp 24

Page 25: 20161206 re growth-tokyo-maroon1st

Amazon States LanguageErrors• エラー発生時のリトライを記述できる

"Retry" : [ { “ErrorEquals”: [ “States.Timeout” ], ← エラーの種類 “IntervalSeconds”: 3, ← リトライ間隔 “MaxAttempts”: 2, ← リトライ数 “BackoffRate”: 1.5 ← エクスポネンシャルバックオフ! }]

classmethod.jp 25

Page 26: 20161206 re growth-tokyo-maroon1st

Amazon States LanguageErrors• スローされた Error のハンドリングも可能

"Catch": [ { "ErrorEquals": [ "java.lang.Exception" ], "ResultPath": "$.error-info", "Next": "RecoveryState" }, { "ErrorEquals": [ "States.ALL" ], "Next": "EndState" }]

classmethod.jp 26

Page 27: 20161206 re growth-tokyo-maroon1st

Amazon States LanguageFilters• 入力、出力、実行結果のデータをフィル

タリング可能

"InputPath": "$.numbers","ResultPath": "$.sum”,"OutputPath": "$"

classmethod.jp 27

Page 28: 20161206 re growth-tokyo-maroon1st

デモ

classmethod.jp 28

Page 29: 20161206 re growth-tokyo-maroon1st

まとめ

• Step Functions は Lambda などを繋げて、大きな処理をワークフローとして実行するサービス

• 処理を状態遷移図として記述すれば Step Functions の設計になる

• 結局は Amazon States Language を覚える必要がある

classmethod.jp 29

Page 30: 20161206 re growth-tokyo-maroon1st