SlideShare a Scribd company logo
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
24th Nov, 2021
見せてやるよ、Step Functions
の本気ってやつをな
@toricls
AWS Expert Online JAWS-UG
@afukui
@_kensh
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Introduce our States.
@toricls
@afukui
@_kensh
Kensuke Shimokawa
Snr. Serverless Specialist
Atsushi Fukui
Snr. Serverless Specialist
Tori Hara
Snr. Dev Advocate, Containers
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ICE BREAK (一言ずつ)
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions を使っていますか?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions の印象は?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions の魅力は?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
本セッションは
想定される聴講者
• AWSをご利用されている事業者、デベロッパー
• AWSを今後利用したビジネスを考えている方
• サーバーレスでの構築に興味がある方
ゴール
• システムでの Step Functions の使い所を理解していただく
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions のかゆいところ
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
JSON (ASL) でワークフローを書くのが大変?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
JSON (ASL) でワークフローを書くのが大変?
{
"StartAt": "Check Stock Price",
"Comment": "An example of itegrating lambda functtions in Step Functions state machine.",
"States": {
"Check Stock Price": {
"Type": "Task",
"Resource": "<CHECK_STOCK_PRICE_LAMBDA_ARN>",
"Next": "Generate Buy/Sell recommendation"
},
"Generate Buy/Sell recommendation": {
"Type": "Task",
"Resource": "<GENERATE_BUY_SELL_RECOMMENDATION_LAMBDA_ARN>",
"ResultPath": "$.recommended_type",
"Next": "Request Human Approval"
},
"Request Human Approval": {
"Type": "Task",
"Resource": "arn:<PARTITION>:states:::sqs:sendMessage.waitForTaskToken",
"Parameters": {
"QueueUrl": "<REQUEST_HUMAN_APPROVAL_SQS_URL>",
"MessageBody": {
"Input.$": "$",
"TaskToken.$": "$$.Task.Token"
}
},
"ResultPath": null,
"Next": "Buy or Sell?"
},
"Buy or Sell?": {
"Type": "Choice",
"Choices": [
{
"Variable": "$.recommended_type",
"StringEquals": "buy",
"Next": "Buy Stock"
},
{
"Variable": "$.recommended_type",
"StringEquals": "sell",
"Next": "Sell Stock"
}
]
},
"Buy Stock": {
"Type": "Task",
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions Workflow Studio によるワークフローの構築
Workflow Studio は、ビジュアルツールを使用
してワークフローをより迅速に開発
https://aws.amazon.com/jp/blogs/news/new-aws-step-functions-workflow-studio-a-low-code-visual-tool-for-building-state-machines/
Data Science
Amazon SageMaker
Amazon EMR
Amazon Athena
Amazon Glue
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Step Functions Data Science SDK による
ワークフローの構築
AWS Step Functions Data Science SDK : Pythonで前処理 - 学習 - デプロイ のワークフローを構築
https://aws.amazon.com/jp/about-aws/whats-new/2019/11/introducing-aws-step-functions-data-science-sdk-amazon-sagemaker/
https://github.com/aws/amazon-sagemaker-examples/
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions が YAML のツールサポートを追加
• 一部ツールにおいてステートマシンの定義に YAML を使えるように
• AWS Toolkit for Visual Studio Code, AWS CloudFormation でサポート
AWS Toolkit for Visual Studio Code AWS CloudFormation
JSON YAML
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
CDK Step Functions コンストラクトの利用
• @aws-cdk/aws-stepfunctions
パッケージには、ワークフローを
構築するためのコンストラクトが
含まれています
• @aws-cdk/aws-stepfunctions-
tasksパッケージには、他のAWS
サービスを呼び出すために使用さ
れるクラスが含まれています
(snip)
const getStatus = new tasks.LambdaInvoke(this, 'Get Job Status', {
lambdaFunction: getStatusLambda,
// Pass just the field named "guid" into the Lambda, put the
// Lambda's result in a field called "status" in the response
inputPath: '$.guid',
outputPath: '$.Payload',
});
const definition = submitJob
.next(waitX)
.next(getStatus)
.next(new sfn.Choice(this, 'Job Complete?')
// Look at the "status" field
.when(sfn.Condition.stringEquals('$.status', 'FAILED'), jobFailed)
.when(sfn.Condition.stringEquals('$.status', 'SUCCEEDED'), finalStatus)
.otherwise(waitX));
new sfn.StateMachine(this, 'StateMachine', {
definition,
timeout: Duration.minutes(5),
});
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions から呼ばれる
Lambda 関数のリポジトリ分け
どうするのが正解?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions から呼ばれる Lambda 関数のリポジトリ分け
AWS Lambda
AWS Lambda
AWS Lambda
AWS Lambda
AWS CodeCommit
どの単位でリポジトリに入れる?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ドメイン駆動設計 (Eric Evans - 2003)
設計における意思決定とドメイン設計
の議論における技術的な用語の広義の
フレームワークを提供
ユビキタス言語
ビジネスドメインエキスパートと開発者の間の
意思疎通として利用される用語によってモデリ
ングと設計を行う
戦略的な設計のためのガイドライン
境界づけられたコンテキストの考察
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
境界づけられたコンテキスト
境界づけられたコンテキストはユビ
キタス言語によって設計されたモデ
ルを適用できる限定された範囲
コンテキストの境界を定めることで
、チームメンバーは何を一致させる
べきで何を独立して開発できるのか
についての理解を明確化し、共有で
きる
https://www.martinfowler.com/bliki/BoundedContext.html
Customer
Ticket
Product
Product
version
Customer
Product
Territory
Opportunity
Pipeline
Salesperson
Defect
Sales context Support context
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コンテキストマップ
Sales context Support context
Marketing context
境界づけられたコンテキストだけでは、ドメインの
全体像を示すことはできない
コンテキストマップは、境界づけられたコンテキスト
を統合することにより、異なるが関連するユビキタス
言語のマッピングを処理する
DDDでは境界づけられたコンテキストを統合するため
の7つのパターンを説明
• 共有カーネル (Shared Kernel)
• 顧客/供給者の開発チーム (Customer/Supplier
Development Teams)
• 順応者 (Conformist)
• 腐敗防止層 (Anticorruption layer)
• 別々の道 (Separate ways)
• 公開ホストサービス (Open/Host service)
• 公表された言語 (Published language)
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions から呼ばれる
Lambda関数のデバッグは
どうやれば良いか?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
ビジネスロジックの配置
ReserveFlight Function
CreateBooking Function
ReserveHotel Function
BookTrip Workflow
広範なスタックで構成された
ビジネスロジック
POST / HTTP/1.1
StartExecution
分散されたロジック
小さなスタックで Unit Test 完結
travelAgent.bookTrip()
reserveFlight()
reserveHotel()
createBooking()
TravelAgent::bookTrip()
ローカルに配置されるロジック
サーバーレス アプリケーション
AWS Step Functions State Machine
これまでのアプリケーション
Class Method
入力バリデーション
+
データ変換
+
ビジネスルール
https://speakerdeck.com/_kensh/serverless-testing-2021?slide=43
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
広範なテストのために必要な変更
Business
logic
handler()
Order
Repository
Business
logic
handler()
Order
Backlog
test()
assert()
act()
assert()
Unit
Tests
Integration Tests
Permissions untested
Unit
Tests
Integration Tests
Permissions untested
Deploy
to test
Deploy
to test
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions の入出力処理
(JSON path syntax) どうやって慣れる?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions の入出力処理
https://docs.aws.amazon.com/step-functions/latest/dg/concepts-input-output-filtering.html
• InputPath では、Task 状態
のタスクにどの JSON 入力
部分を渡すかを選択
• ResultPath を使用して、出
力に渡す状態入力とタスク
結果の組み合わせを選択
• OutputPath では、JSON 出
力をフィルタリングして、
出力に渡される情報を絞り
込む
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Data flow simulator
各Stateは、JSONを受け取
り、出力としてJSONを次
の状態に渡します
• データが状態から状態へとど
のように流れるかを理解する
• データをフィルタリングおよ
び操作する方法を学ぶ
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
builders.flash
https://aws.amazon.com/jp/builders-flash/202104/stepfunctions-fizzbuzz
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions にまつわる
学校で友達に自慢したくなること
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions で
復元力のあるAWS Fargate Task 実行って?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Fargate with Step Functions
3. Fargate Task の「stoppedReason」
に基づく詳細なエラー処理
2. 並列化された Fargate Task
1. 復元力のあるスケジュールされた
Fargate Task
「リトライ」機能を使用
Map State を使用して、パラメータ化された
Fargate Task を実行
エラーが ResourceInitializationError の場合は再試行
CannotPullContainerError の場合は失敗
https://github.com/toricls/aws-fargate-with-step-functions
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
オンプレミスのジョブとどうやって連携する?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Callback ワークフロー
AWS Step Functions workflow
Start
Notify
End
ワークフロー
Job
Notify
Event
(time-based)
オンプレミス
サーバー
Queue Lambda function
Token, Param
Token, Result
OR
Tokenを外部サービスに連携して、
コールバック待機可能
Amazon Elastic Container
Service (Amazon ECS)
https://docs.aws.amazon.com/ja_jp/step-functions/latest/dg/callback-task-sample-sqs.html
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
並列ジョブをどうやって実装する?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Lambda 関数ジョブの並列化 with Map
AWS Step Functions workflow
Start
End
ワークフロー
Transform
Load
Event
(time-based)
S3
Extract function
Transform function
Load function
Transform
Load
Extract
Transform
Load
Map
Lambda関数でのETLを Map State により並列化
[data1, data2, …, dataN]
https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-
language-map-state.html
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step FunctionsをAPI処理に使える?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
軽量 ETL オーケストレーション として使う
AWS Step Functions workflow
Start
Extract
End
ワークフロー
Transform
Load
Amazon
API Gateway
より軽量で短時間なETL処理であれば、
API Gateway から同期的にワークフローをコールする
ことも可能
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
BFF(Backends For Frontends)として使う
AWS Step Functions workflow
Start
API
End
ワークフロー
API
API
Amazon
API Gateway
API Gatewayから同期的に
Express ワークフローを
コールする
Mobile
client
オンプレミス
サーバー
Lambda function
Amazon Elastic Container
Service (Amazon ECS)
BFF
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
非同期パターン として使う with WebSockets
サーバーからクライアントへ WebSockets による通知を
行い、 よりタイムリーに実行結果を送信
Step Functions workflow
onConnect
API Gateway
(WebSockets)
Step Functions
Lambda
API Gateway
Mobile
client
https://aws.amazon.com/blogs/compute/from-poll-to-push-transform-apis-using-amazon-api-gateway-rest-apis-and-websockets/
API Gatewayから非同期にワークフローを
実行する
Amazon DynamoDB
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
デザインパターンの視点を考えたい
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
自律的に処理をコントロールするには?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コレオグラフィーパターンとは
• 必要なすべての情報を含んだ最初のイベントを 1 つのメッセージに保存し
て、最初のトランザクションを完了
• 他のサービスがそのメッセージを非同期的に取得し、それぞれのタスクを
完了させる
• サービスが疎結合になり、直接互いに影響を与えない
• メッセージの保存と取得が非同期の関係になり、スケーラビリティと信頼
性が向上
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コレオグラフィーパターン
ユーザー
リクエストサービス リクエストキュー
サービスA
サービスB
サービスC
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
実装例1: SNS、 SQS、 Lambdaの利用
ユーザー
リクエストサービス Amazon
SNS
Amazon SQS
Amazon SQS
Amazon SQS
AWS Lambda
AWS Lambda
AWS Lambda
ファンアウト
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
実装例2: Amazon EventBridgeの利用 配送
ポイント
プレミアム会員
カート
支払
支払い方法
認証
注文
1分毎に実行
Events
会員
ステータス
支払認証
カートに
入れる
注文完了
Amazon
EventBridge
リクエストサービス イベントバス
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
中央で処理をコントロールするには?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コレオグラフィーとオーケストレーション
ユーザー
リクエストサービス リクエストキュー
サービスA
サービスB
サービスC
サービスA
サービスB
サービスC
ユーザー リクエストサービス
Step Functions workflow
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
オーケストレーション
口座申請
口座
データ
チェック
人による
確認
IDをチェック
アドレスのチェック
人による確認
口座の作成
1つのプロセスがワークフローの状態を管理し、
適切なサービスを順番に呼び出す
Step Functions で実装可能
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
長期トランザクションを管理するには?
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Sagaパターン
• ”Saga内のトランザクションは相互に関連しており、(非アトミックな)ユニット
として実行する必要がある。Sagaの部分的な実行は望ましくなく、エラーが発生
した場合は補償する必要がある。”
• 部分的な実行を修正するには、各SagaトランザクションT(i)に補償
トランザクションC(i)を提供する必要がある。
• 補償トランザクションは、セマンティックの観点から、T(i)によって実行されたア
クションをすべて元に戻すが、(他のトランザクションによって変更されている可
能性があるため)データベースをT(i)の実行が開始されたときに存在していた
状態に戻すとは限らない。
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Sagaの実装
• アプリケーションプログラマの観点からは、Sagaの開始と終了、各トランザク
ションの開始と終了、および補償トランザクションをシステムに知らせるため
のメカニズムが必要
• SagaトランザクションIDや補償トランザクションの名前、エントリポイント、
補償トランザクションに必要なパラメータ、セーブポイントなどを保持する必
要がある
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Sagaの実装(バックワードリカバリ)
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Sagaの実装 (フォワードリカバリとSave Point)
注意:常に可能であるとは限らない
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Sagaと並列トランザクション
• Sagaは並列トランザクションを含むように拡張することが可能
• 並列Sagaの各プロセス内で、トランザクションはシーケンシャルなSagaと同様
に逆の順序で補償
• 子プロセスのすべての補償は、子プロセスの作成前に実行された
親トランザクションの補償の前に発生する必要がある
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
マイクロサービスアーキテクチャと共に再び注目
• Chris RichardsonがMicroservices PatternsでSagaパターンを取り上げたこと
で再び注目を浴びる(*)
• Pattern: Saga (**)
• マイクロサービスで典型的な Database per Serviceパターンを適用している
場合、個々のマイクロサービス内ではACIDトランザクションを利用出来る
が、サービスをまたがるトランザクションを管理する仕組みが必要
• => Sagaパターン
• 実装例としてコレオグラフィベースのSagaとオーケストレーションベースの
Sagaを紹介 (*) https://microservices.io/index.html
(**) https://microservices.io/patterns/data/saga.html
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions による Saga パターンの実装
https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/implement-the-serverless-saga-pattern-by-using-aws-step-functions.html
このパターンは、図で強調表示されている
タスクごとに Lambda関数と、3つの
DynamoDBテーブルをデプロイします。
各Lambda関数は、トランザクションがコ
ミットされたかロールバックされたかに応
じて、対応するDynamoDBテーブルのitem
を作成、更新、削除します。
Amazon SNSを使用してテキスト(SMS)
メッセージをサブスクライバーに送信し、
トランザクションの失敗または成功を通知
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
コードフリーな世界観に浸りたい
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Step Functions が AWS SDK との統合をサポート
AWS Step Functions Express Workflows
Start
End
GetSampleVideo
GetTranscriptionText
• 200+のサービス、9000+の API
アクションを新たにサポート
• カスタムコードの記述不要で、SDK で
提供されている API を呼び出せる
• ASL 組み込み関数を使って
データを変換することができる
• ほとんの場合 IAM ポリシーは自動生成
されないので、明示的に追加する必要
がある
ポイント
AWS SDK
サポートされているサービス一覧
https://docs.aws.amazon.com/step-functions/latest/dg/supported-services-awssdk.html
StartTextTranslation
StartTranscriptionJob
Amazon Transcribe
Amazon Translate
s3:copyObject
transcribe:startTranscriptionJob
s3:getObject
translate:translateText
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
EventBridge のターゲットに
新機能 API Destinations を指定可能に
ポイント
• 任意のエンドポイントに対して
HTTPリクエストを送ることができる
• コードの実装は不要
• 3種類の認証タイプ (Basic認証 / OAuth
クライアントクレデンシャル / API
キー) を利用可能。クレデンシャルは
AWS Secrets Manager で管理。
• 入力値のカスタマイズやリトライ、
呼び出しレートの調整も可能
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
まとめ
• Step Functions はサーバーレスなワークフローであり、ご利用した分の課金
になります。
• マイクロサービスをオーケストレーションしたい場合、Step Functions で処
理を制御することにより、可視化されたワークフローを体験できます。
• サーバーレスサービスの中でも特に進化の早いサービスの一つとなってお
り、多くのユースケースで使われています。
@_kensh
© 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Thank you!
@toricls
@afukui
@_kensh

More Related Content

PDF
20200630 AWS Black Belt Online Seminar Amazon Cognito
PDF
20210216 AWS Black Belt Online Seminar AWS Database Migration Service
PDF
20190522 AWS Black Belt Online Seminar AWS Step Functions
PDF
20190514 AWS Black Belt Online Seminar Amazon API Gateway
PDF
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design Pattern
PDF
20190814 AWS Black Belt Online Seminar AWS Serverless Application Model
PDF
AWS Black Belt Online Seminar 2017 Amazon Kinesis
PDF
20200826 AWS Black Belt Online Seminar AWS CloudFormation
20200630 AWS Black Belt Online Seminar Amazon Cognito
20210216 AWS Black Belt Online Seminar AWS Database Migration Service
20190522 AWS Black Belt Online Seminar AWS Step Functions
20190514 AWS Black Belt Online Seminar Amazon API Gateway
AWS Black Belt Online Seminar 2018 Amazon DynamoDB Advanced Design Pattern
20190814 AWS Black Belt Online Seminar AWS Serverless Application Model
AWS Black Belt Online Seminar 2017 Amazon Kinesis
20200826 AWS Black Belt Online Seminar AWS CloudFormation

What's hot (20)

PDF
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
PDF
20190911 AWS Black Belt Online Seminar AWS Batch
PDF
20190806 AWS Black Belt Online Seminar AWS Glue
PDF
20180509 AWS Black Belt Online Seminar Amazon GuardDuty
PDF
AWSのログ管理ベストプラクティス
PDF
20210330 AWS Black Belt Online Seminar AWS Glue -Glue Studioを使ったデータ変換のベストプラクティス-
PDF
20190604 AWS Black Belt Online Seminar Amazon Simple Notification Service (SNS)
PDF
Kinesis + Elasticsearchでつくるさいきょうのログ分析基盤
PDF
DevOps with Database on AWS
PDF
20200526 AWS Black Belt Online Seminar AWS X-Ray
PDF
20190730 AWS Black Belt Online Seminar Amazon CloudFrontの概要
PDF
20201111 AWS Black Belt Online Seminar AWS CodeStar & AWS CodePipeline
PDF
20180704(20190520 Renewed) AWS Black Belt Online Seminar Amazon Elastic File ...
PDF
20190130 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...
PPTX
20220409 AWS BLEA 開発にあたって検討したこと
PDF
Infrastructure as Code (IaC) 談義 2022
PDF
20190821 AWS Black Belt Online Seminar AWS AppSync
PDF
20190326 AWS Black Belt Online Seminar Amazon CloudWatch
PDF
20210526 AWS Expert Online マルチアカウント管理の基本
PDF
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ
[Aurora事例祭り]Amazon Aurora を使いこなすためのベストプラクティス
20190911 AWS Black Belt Online Seminar AWS Batch
20190806 AWS Black Belt Online Seminar AWS Glue
20180509 AWS Black Belt Online Seminar Amazon GuardDuty
AWSのログ管理ベストプラクティス
20210330 AWS Black Belt Online Seminar AWS Glue -Glue Studioを使ったデータ変換のベストプラクティス-
20190604 AWS Black Belt Online Seminar Amazon Simple Notification Service (SNS)
Kinesis + Elasticsearchでつくるさいきょうのログ分析基盤
DevOps with Database on AWS
20200526 AWS Black Belt Online Seminar AWS X-Ray
20190730 AWS Black Belt Online Seminar Amazon CloudFrontの概要
20201111 AWS Black Belt Online Seminar AWS CodeStar & AWS CodePipeline
20180704(20190520 Renewed) AWS Black Belt Online Seminar Amazon Elastic File ...
20190130 AWS Black Belt Online Seminar AWS Identity and Access Management (AW...
20220409 AWS BLEA 開発にあたって検討したこと
Infrastructure as Code (IaC) 談義 2022
20190821 AWS Black Belt Online Seminar AWS AppSync
20190326 AWS Black Belt Online Seminar Amazon CloudWatch
20210526 AWS Expert Online マルチアカウント管理の基本
機密データとSaaSは共存しうるのか!?セキュリティー重視のユーザー層を取り込む為のネットワーク通信のアプローチ
Ad

Similar to [AWS EXpert Online for JAWS-UG 18] 見せてやるよ、Step Functions の本気ってやつをな (20)

PDF
20170726 black belt_stepfunctions
PDF
JAWSUG Kansai Simple Workflow Service (SWF)
PPTX
Amazon SimpleWorkflowのご紹介
PPTX
20161206 re growth-tokyo-maroon1st
PDF
不安定な環境の中でのバッチ処理~JobQueueシステムQudoを使った事例~
PDF
[AWSマイスターシリーズ]Amazon Simple Workflow Service (SWF)
PPTX
Containers + EC2 Spot: AWS Batch による大規模バッチ処理でのスポットインスタンス活用
PDF
Amazon Simple Workflow Service (SWF)
PDF
AWS Lambda Update
PDF
[CTO Night & Day 2019] よくある課題を一気に解説!御社の技術レベルがアップする 2019 秋期講習 #ctonight
PDF
Cloudnative online-2021-stepfunction
PDF
Im workflow説明資料(patch01対応)
PDF
[JAWS-UG 三都物語 2014] 三都物語でAmazon SWFと握手!
PDF
DevLOVE発表資料
PDF
SWF
PPTX
Clrh 20121215
PPT
YAWL - Tokyo 2008 - Petia Wohed
PDF
AWS Black Belt Techシリーズ AWS Lambda
PDF
Aws step functionsのい・ろ・は
PDF
20200728 AWS Black Belt Online Seminar What's New in Serverless
20170726 black belt_stepfunctions
JAWSUG Kansai Simple Workflow Service (SWF)
Amazon SimpleWorkflowのご紹介
20161206 re growth-tokyo-maroon1st
不安定な環境の中でのバッチ処理~JobQueueシステムQudoを使った事例~
[AWSマイスターシリーズ]Amazon Simple Workflow Service (SWF)
Containers + EC2 Spot: AWS Batch による大規模バッチ処理でのスポットインスタンス活用
Amazon Simple Workflow Service (SWF)
AWS Lambda Update
[CTO Night & Day 2019] よくある課題を一気に解説!御社の技術レベルがアップする 2019 秋期講習 #ctonight
Cloudnative online-2021-stepfunction
Im workflow説明資料(patch01対応)
[JAWS-UG 三都物語 2014] 三都物語でAmazon SWFと握手!
DevLOVE発表資料
SWF
Clrh 20121215
YAWL - Tokyo 2008 - Petia Wohed
AWS Black Belt Techシリーズ AWS Lambda
Aws step functionsのい・ろ・は
20200728 AWS Black Belt Online Seminar What's New in Serverless
Ad

More from Amazon Web Services Japan (20)

PDF
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)
PDF
202205 AWS Black Belt Online Seminar Amazon FSx for OpenZFS
PDF
202204 AWS Black Belt Online Seminar AWS IoT Device Defender
PDF
202204 AWS Black Belt Online Seminar Amazon Connect を活用したオンコール対応の実現
PDF
202204 AWS Black Belt Online Seminar Amazon Connect Salesforce連携(第1回 CTI Adap...
PDF
Amazon Game Tech Night #25 ゲーム業界向け機械学習最新状況アップデート
PDF
202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用
PDF
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf
PDF
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介
PDF
Amazon QuickSight の組み込み方法をちょっぴりDD
PDF
マルチテナント化で知っておきたいデータベースのこと
PDF
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介
PDF
202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles
PDF
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するために
PDF
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨
PPTX
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
PDF
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介
PDF
202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...
PDF
202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ
PDF
20211209 Ops-JAWS Re invent2021re-cap-cloud operations
202205 AWS Black Belt Online Seminar Amazon VPC IP Address Manager (IPAM)
202205 AWS Black Belt Online Seminar Amazon FSx for OpenZFS
202204 AWS Black Belt Online Seminar AWS IoT Device Defender
202204 AWS Black Belt Online Seminar Amazon Connect を活用したオンコール対応の実現
202204 AWS Black Belt Online Seminar Amazon Connect Salesforce連携(第1回 CTI Adap...
Amazon Game Tech Night #25 ゲーム業界向け機械学習最新状況アップデート
202202 AWS Black Belt Online Seminar AWS Managed Rules for AWS WAF の活用
202203 AWS Black Belt Online Seminar Amazon Connect Tasks.pdf
SaaS テナント毎のコストを把握するための「AWS Application Cost Profiler」のご紹介
Amazon QuickSight の組み込み方法をちょっぴりDD
マルチテナント化で知っておきたいデータベースのこと
パッケージソフトウェアを簡単にSaaS化!?既存の資産を使ったSaaS化手法のご紹介
202202 AWS Black Belt Online Seminar Amazon Connect Customer Profiles
Amazon Game Tech Night #24 KPIダッシュボードを最速で用意するために
202202 AWS Black Belt Online Seminar AWS SaaS Boost で始めるSaaS開発⼊⾨
[20220126] JAWS-UG 2022初頭までに葬ったAWSアンチパターン大紹介
202111 AWS Black Belt Online Seminar AWSで構築するSmart Mirrorのご紹介
202201 AWS Black Belt Online Seminar Apache Spark Performnace Tuning for AWS ...
202112 AWS Black Belt Online Seminar 店内の「今」をお届けする小売業向けリアルタイム配信基盤のレシピ
20211209 Ops-JAWS Re invent2021re-cap-cloud operations

[AWS EXpert Online for JAWS-UG 18] 見せてやるよ、Step Functions の本気ってやつをな

  • 1. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 24th Nov, 2021 見せてやるよ、Step Functions の本気ってやつをな @toricls AWS Expert Online JAWS-UG @afukui @_kensh
  • 2. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Introduce our States. @toricls @afukui @_kensh Kensuke Shimokawa Snr. Serverless Specialist Atsushi Fukui Snr. Serverless Specialist Tori Hara Snr. Dev Advocate, Containers
  • 3. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ICE BREAK (一言ずつ)
  • 4. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions を使っていますか?
  • 5. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 6. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions の印象は?
  • 7. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 8. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions の魅力は?
  • 9. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 10. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 本セッションは 想定される聴講者 • AWSをご利用されている事業者、デベロッパー • AWSを今後利用したビジネスを考えている方 • サーバーレスでの構築に興味がある方 ゴール • システムでの Step Functions の使い所を理解していただく
  • 11. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions のかゆいところ
  • 12. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. JSON (ASL) でワークフローを書くのが大変?
  • 13. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. JSON (ASL) でワークフローを書くのが大変? { "StartAt": "Check Stock Price", "Comment": "An example of itegrating lambda functtions in Step Functions state machine.", "States": { "Check Stock Price": { "Type": "Task", "Resource": "<CHECK_STOCK_PRICE_LAMBDA_ARN>", "Next": "Generate Buy/Sell recommendation" }, "Generate Buy/Sell recommendation": { "Type": "Task", "Resource": "<GENERATE_BUY_SELL_RECOMMENDATION_LAMBDA_ARN>", "ResultPath": "$.recommended_type", "Next": "Request Human Approval" }, "Request Human Approval": { "Type": "Task", "Resource": "arn:<PARTITION>:states:::sqs:sendMessage.waitForTaskToken", "Parameters": { "QueueUrl": "<REQUEST_HUMAN_APPROVAL_SQS_URL>", "MessageBody": { "Input.$": "$", "TaskToken.$": "$$.Task.Token" } }, "ResultPath": null, "Next": "Buy or Sell?" }, "Buy or Sell?": { "Type": "Choice", "Choices": [ { "Variable": "$.recommended_type", "StringEquals": "buy", "Next": "Buy Stock" }, { "Variable": "$.recommended_type", "StringEquals": "sell", "Next": "Sell Stock" } ] }, "Buy Stock": { "Type": "Task",
  • 14. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions Workflow Studio によるワークフローの構築 Workflow Studio は、ビジュアルツールを使用 してワークフローをより迅速に開発 https://aws.amazon.com/jp/blogs/news/new-aws-step-functions-workflow-studio-a-low-code-visual-tool-for-building-state-machines/ Data Science Amazon SageMaker Amazon EMR Amazon Athena Amazon Glue
  • 15. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Step Functions Data Science SDK による ワークフローの構築 AWS Step Functions Data Science SDK : Pythonで前処理 - 学習 - デプロイ のワークフローを構築 https://aws.amazon.com/jp/about-aws/whats-new/2019/11/introducing-aws-step-functions-data-science-sdk-amazon-sagemaker/ https://github.com/aws/amazon-sagemaker-examples/
  • 16. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions が YAML のツールサポートを追加 • 一部ツールにおいてステートマシンの定義に YAML を使えるように • AWS Toolkit for Visual Studio Code, AWS CloudFormation でサポート AWS Toolkit for Visual Studio Code AWS CloudFormation JSON YAML
  • 17. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. CDK Step Functions コンストラクトの利用 • @aws-cdk/aws-stepfunctions パッケージには、ワークフローを 構築するためのコンストラクトが 含まれています • @aws-cdk/aws-stepfunctions- tasksパッケージには、他のAWS サービスを呼び出すために使用さ れるクラスが含まれています (snip) const getStatus = new tasks.LambdaInvoke(this, 'Get Job Status', { lambdaFunction: getStatusLambda, // Pass just the field named "guid" into the Lambda, put the // Lambda's result in a field called "status" in the response inputPath: '$.guid', outputPath: '$.Payload', }); const definition = submitJob .next(waitX) .next(getStatus) .next(new sfn.Choice(this, 'Job Complete?') // Look at the "status" field .when(sfn.Condition.stringEquals('$.status', 'FAILED'), jobFailed) .when(sfn.Condition.stringEquals('$.status', 'SUCCEEDED'), finalStatus) .otherwise(waitX)); new sfn.StateMachine(this, 'StateMachine', { definition, timeout: Duration.minutes(5), });
  • 18. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions から呼ばれる Lambda 関数のリポジトリ分け どうするのが正解?
  • 19. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions から呼ばれる Lambda 関数のリポジトリ分け AWS Lambda AWS Lambda AWS Lambda AWS Lambda AWS CodeCommit どの単位でリポジトリに入れる?
  • 20. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ドメイン駆動設計 (Eric Evans - 2003) 設計における意思決定とドメイン設計 の議論における技術的な用語の広義の フレームワークを提供 ユビキタス言語 ビジネスドメインエキスパートと開発者の間の 意思疎通として利用される用語によってモデリ ングと設計を行う 戦略的な設計のためのガイドライン 境界づけられたコンテキストの考察
  • 21. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 境界づけられたコンテキスト 境界づけられたコンテキストはユビ キタス言語によって設計されたモデ ルを適用できる限定された範囲 コンテキストの境界を定めることで 、チームメンバーは何を一致させる べきで何を独立して開発できるのか についての理解を明確化し、共有で きる https://www.martinfowler.com/bliki/BoundedContext.html Customer Ticket Product Product version Customer Product Territory Opportunity Pipeline Salesperson Defect Sales context Support context
  • 22. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. コンテキストマップ Sales context Support context Marketing context 境界づけられたコンテキストだけでは、ドメインの 全体像を示すことはできない コンテキストマップは、境界づけられたコンテキスト を統合することにより、異なるが関連するユビキタス 言語のマッピングを処理する DDDでは境界づけられたコンテキストを統合するため の7つのパターンを説明 • 共有カーネル (Shared Kernel) • 顧客/供給者の開発チーム (Customer/Supplier Development Teams) • 順応者 (Conformist) • 腐敗防止層 (Anticorruption layer) • 別々の道 (Separate ways) • 公開ホストサービス (Open/Host service) • 公表された言語 (Published language)
  • 23. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions から呼ばれる Lambda関数のデバッグは どうやれば良いか?
  • 24. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. ビジネスロジックの配置 ReserveFlight Function CreateBooking Function ReserveHotel Function BookTrip Workflow 広範なスタックで構成された ビジネスロジック POST / HTTP/1.1 StartExecution 分散されたロジック 小さなスタックで Unit Test 完結 travelAgent.bookTrip() reserveFlight() reserveHotel() createBooking() TravelAgent::bookTrip() ローカルに配置されるロジック サーバーレス アプリケーション AWS Step Functions State Machine これまでのアプリケーション Class Method 入力バリデーション + データ変換 + ビジネスルール https://speakerdeck.com/_kensh/serverless-testing-2021?slide=43
  • 25. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 広範なテストのために必要な変更 Business logic handler() Order Repository Business logic handler() Order Backlog test() assert() act() assert() Unit Tests Integration Tests Permissions untested Unit Tests Integration Tests Permissions untested Deploy to test Deploy to test
  • 26. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions の入出力処理 (JSON path syntax) どうやって慣れる?
  • 27. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions の入出力処理 https://docs.aws.amazon.com/step-functions/latest/dg/concepts-input-output-filtering.html • InputPath では、Task 状態 のタスクにどの JSON 入力 部分を渡すかを選択 • ResultPath を使用して、出 力に渡す状態入力とタスク 結果の組み合わせを選択 • OutputPath では、JSON 出 力をフィルタリングして、 出力に渡される情報を絞り 込む
  • 28. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Data flow simulator 各Stateは、JSONを受け取 り、出力としてJSONを次 の状態に渡します • データが状態から状態へとど のように流れるかを理解する • データをフィルタリングおよ び操作する方法を学ぶ
  • 29. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. builders.flash https://aws.amazon.com/jp/builders-flash/202104/stepfunctions-fizzbuzz
  • 30. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions にまつわる 学校で友達に自慢したくなること
  • 31. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions で 復元力のあるAWS Fargate Task 実行って?
  • 32. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Fargate with Step Functions 3. Fargate Task の「stoppedReason」 に基づく詳細なエラー処理 2. 並列化された Fargate Task 1. 復元力のあるスケジュールされた Fargate Task 「リトライ」機能を使用 Map State を使用して、パラメータ化された Fargate Task を実行 エラーが ResourceInitializationError の場合は再試行 CannotPullContainerError の場合は失敗 https://github.com/toricls/aws-fargate-with-step-functions
  • 33. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. オンプレミスのジョブとどうやって連携する?
  • 34. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Callback ワークフロー AWS Step Functions workflow Start Notify End ワークフロー Job Notify Event (time-based) オンプレミス サーバー Queue Lambda function Token, Param Token, Result OR Tokenを外部サービスに連携して、 コールバック待機可能 Amazon Elastic Container Service (Amazon ECS) https://docs.aws.amazon.com/ja_jp/step-functions/latest/dg/callback-task-sample-sqs.html
  • 35. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 並列ジョブをどうやって実装する?
  • 36. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Lambda 関数ジョブの並列化 with Map AWS Step Functions workflow Start End ワークフロー Transform Load Event (time-based) S3 Extract function Transform function Load function Transform Load Extract Transform Load Map Lambda関数でのETLを Map State により並列化 [data1, data2, …, dataN] https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states- language-map-state.html
  • 37. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step FunctionsをAPI処理に使える?
  • 38. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 軽量 ETL オーケストレーション として使う AWS Step Functions workflow Start Extract End ワークフロー Transform Load Amazon API Gateway より軽量で短時間なETL処理であれば、 API Gateway から同期的にワークフローをコールする ことも可能
  • 39. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. BFF(Backends For Frontends)として使う AWS Step Functions workflow Start API End ワークフロー API API Amazon API Gateway API Gatewayから同期的に Express ワークフローを コールする Mobile client オンプレミス サーバー Lambda function Amazon Elastic Container Service (Amazon ECS) BFF
  • 40. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 非同期パターン として使う with WebSockets サーバーからクライアントへ WebSockets による通知を 行い、 よりタイムリーに実行結果を送信 Step Functions workflow onConnect API Gateway (WebSockets) Step Functions Lambda API Gateway Mobile client https://aws.amazon.com/blogs/compute/from-poll-to-push-transform-apis-using-amazon-api-gateway-rest-apis-and-websockets/ API Gatewayから非同期にワークフローを 実行する Amazon DynamoDB
  • 41. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. デザインパターンの視点を考えたい
  • 42. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 自律的に処理をコントロールするには?
  • 43. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. コレオグラフィーパターンとは • 必要なすべての情報を含んだ最初のイベントを 1 つのメッセージに保存し て、最初のトランザクションを完了 • 他のサービスがそのメッセージを非同期的に取得し、それぞれのタスクを 完了させる • サービスが疎結合になり、直接互いに影響を与えない • メッセージの保存と取得が非同期の関係になり、スケーラビリティと信頼 性が向上
  • 44. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. コレオグラフィーパターン ユーザー リクエストサービス リクエストキュー サービスA サービスB サービスC
  • 45. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 実装例1: SNS、 SQS、 Lambdaの利用 ユーザー リクエストサービス Amazon SNS Amazon SQS Amazon SQS Amazon SQS AWS Lambda AWS Lambda AWS Lambda ファンアウト
  • 46. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 実装例2: Amazon EventBridgeの利用 配送 ポイント プレミアム会員 カート 支払 支払い方法 認証 注文 1分毎に実行 Events 会員 ステータス 支払認証 カートに 入れる 注文完了 Amazon EventBridge リクエストサービス イベントバス
  • 47. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 中央で処理をコントロールするには?
  • 48. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. コレオグラフィーとオーケストレーション ユーザー リクエストサービス リクエストキュー サービスA サービスB サービスC サービスA サービスB サービスC ユーザー リクエストサービス Step Functions workflow
  • 49. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. オーケストレーション 口座申請 口座 データ チェック 人による 確認 IDをチェック アドレスのチェック 人による確認 口座の作成 1つのプロセスがワークフローの状態を管理し、 適切なサービスを順番に呼び出す Step Functions で実装可能
  • 50. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. 長期トランザクションを管理するには?
  • 51. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Sagaパターン • ”Saga内のトランザクションは相互に関連しており、(非アトミックな)ユニット として実行する必要がある。Sagaの部分的な実行は望ましくなく、エラーが発生 した場合は補償する必要がある。” • 部分的な実行を修正するには、各SagaトランザクションT(i)に補償 トランザクションC(i)を提供する必要がある。 • 補償トランザクションは、セマンティックの観点から、T(i)によって実行されたア クションをすべて元に戻すが、(他のトランザクションによって変更されている可 能性があるため)データベースをT(i)の実行が開始されたときに存在していた 状態に戻すとは限らない。
  • 52. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Sagaの実装 • アプリケーションプログラマの観点からは、Sagaの開始と終了、各トランザク ションの開始と終了、および補償トランザクションをシステムに知らせるため のメカニズムが必要 • SagaトランザクションIDや補償トランザクションの名前、エントリポイント、 補償トランザクションに必要なパラメータ、セーブポイントなどを保持する必 要がある
  • 53. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Sagaの実装(バックワードリカバリ)
  • 54. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Sagaの実装 (フォワードリカバリとSave Point) 注意:常に可能であるとは限らない
  • 55. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Sagaと並列トランザクション • Sagaは並列トランザクションを含むように拡張することが可能 • 並列Sagaの各プロセス内で、トランザクションはシーケンシャルなSagaと同様 に逆の順序で補償 • 子プロセスのすべての補償は、子プロセスの作成前に実行された 親トランザクションの補償の前に発生する必要がある
  • 56. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. マイクロサービスアーキテクチャと共に再び注目 • Chris RichardsonがMicroservices PatternsでSagaパターンを取り上げたこと で再び注目を浴びる(*) • Pattern: Saga (**) • マイクロサービスで典型的な Database per Serviceパターンを適用している 場合、個々のマイクロサービス内ではACIDトランザクションを利用出来る が、サービスをまたがるトランザクションを管理する仕組みが必要 • => Sagaパターン • 実装例としてコレオグラフィベースのSagaとオーケストレーションベースの Sagaを紹介 (*) https://microservices.io/index.html (**) https://microservices.io/patterns/data/saga.html
  • 57. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions による Saga パターンの実装 https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/implement-the-serverless-saga-pattern-by-using-aws-step-functions.html このパターンは、図で強調表示されている タスクごとに Lambda関数と、3つの DynamoDBテーブルをデプロイします。 各Lambda関数は、トランザクションがコ ミットされたかロールバックされたかに応 じて、対応するDynamoDBテーブルのitem を作成、更新、削除します。 Amazon SNSを使用してテキスト(SMS) メッセージをサブスクライバーに送信し、 トランザクションの失敗または成功を通知
  • 58. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. コードフリーな世界観に浸りたい
  • 59. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Step Functions が AWS SDK との統合をサポート AWS Step Functions Express Workflows Start End GetSampleVideo GetTranscriptionText • 200+のサービス、9000+の API アクションを新たにサポート • カスタムコードの記述不要で、SDK で 提供されている API を呼び出せる • ASL 組み込み関数を使って データを変換することができる • ほとんの場合 IAM ポリシーは自動生成 されないので、明示的に追加する必要 がある ポイント AWS SDK サポートされているサービス一覧 https://docs.aws.amazon.com/step-functions/latest/dg/supported-services-awssdk.html StartTextTranslation StartTranscriptionJob Amazon Transcribe Amazon Translate s3:copyObject transcribe:startTranscriptionJob s3:getObject translate:translateText
  • 60. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. EventBridge のターゲットに 新機能 API Destinations を指定可能に ポイント • 任意のエンドポイントに対して HTTPリクエストを送ることができる • コードの実装は不要 • 3種類の認証タイプ (Basic認証 / OAuth クライアントクレデンシャル / API キー) を利用可能。クレデンシャルは AWS Secrets Manager で管理。 • 入力値のカスタマイズやリトライ、 呼び出しレートの調整も可能
  • 61. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
  • 62. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. まとめ • Step Functions はサーバーレスなワークフローであり、ご利用した分の課金 になります。 • マイクロサービスをオーケストレーションしたい場合、Step Functions で処 理を制御することにより、可視化されたワークフローを体験できます。 • サーバーレスサービスの中でも特に進化の早いサービスの一つとなってお り、多くのユースケースで使われています。
  • 64. © 2021, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Thank you! @toricls @afukui @_kensh