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
今日から使える AWS Step Functions 小技集 / AWS Step Funct...
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Masanori Yamaguchi
December 08, 2025
Technology
850
8
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
今日から使える AWS Step Functions 小技集 / AWS Step Functions Tips
Masanori Yamaguchi
December 08, 2025
More Decks by Masanori Yamaguchi
See All by Masanori Yamaguchi
AWS DevOps Agentはチームメイトになれるのか?/ Can AWS DevOps Agent become a teammate
kinunori
7
920
AWS DevOps Agent x ECS on Fargate検証 / AWS DevOps Agent x ECS on Fargate
kinunori
4
770
AWS DevOps Agent 検証で見えた可能性と限界 / AWS DevOps Agent
kinunori
6
2.1k
AWS re:Invent 2025事前勉強会資料 / AWS re:Invent 2025 pre study meetup
kinunori
0
2.7k
AWS Well-Architected なインシデントレスポンスを実装しよう / Implementing Incident Response with AWS Well-Architected
kinunori
2
880
pre:Invent から気になった サービスを深掘りしてみる- ECS 予測スケーリング編 / ECS-predictive-scaling
kinunori
2
300
JAWS-UG 函館 Dr.Wernerの基調講演で振り返る "推測するな、計測せよ" / JAWS-UG Hakodate re:Invent 2024 recap
kinunori
2
140
Share your lessons - 20241217 AWS Ambassador & Top Engineer LT
kinunori
0
130
re:Invent 2024 事前勉強会 / re:Invent 2024 stby
kinunori
2
1.3k
Other Decks in Technology
See All in Technology
Chart.js が簡単に使えるようになっていたので OGP 画像生成に使った話
kamekyame
0
160
Amazon Bedrock AgentCore ワークショップ JAWS UG TOHOKU / amazon-bedrock-agentcore-workshop-jawsug-tohoku-2026
gawa
8
320
Rubyで音を視る
ydah
1
100
LLMと共に進化するプロセスを目指して
ymatsuwitter
12
3.3k
正解のないAIプロダクトをどう導くか?dodaが挑む、ユーザーの『本音』を構造化する評価設計と検証のリアル
techtekt
PRO
0
180
MIERUNE JCT 発表資料「宇宙から伊能忠敬ごっこ」
syuchimu
0
190
AIにフローを作らせようとして挫折した話
hamatsutaichi
0
200
GoとSIMDとWasmの今。
askua
3
510
Rancherの紹介&Update情報(RancherJP Online Meetup #09)
yoshiyuki_kono
0
110
PHP と TypeScript の型システム比較:AI 時代の「型」は誰のためにあるのか? #frontend_phpcon_do / frontend_phpcon_do_2026
shogogg
1
250
OCI Oracle AI Database Services新機能アップデート(2026/03-2026/05)
oracle4engineer
PRO
0
240
Oracle AI Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
6
1.5k
Featured
See All Featured
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
150
Tips & Tricks on How to Get Your First Job In Tech
honzajavorek
1
530
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
Google's AI Overviews - The New Search
badams
0
1k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.5k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Code Review Best Practice
trishagee
74
20k
Fireside Chat
paigeccino
42
3.9k
How STYLIGHT went responsive
nonsquared
100
6.2k
Self-Hosted WebAssembly Runtime for Runtime-Neutral Checkpoint/Restore in Edge–Cloud Continuum
chikuwait
0
570
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.2k
Site-Speed That Sticks
csswizardry
13
1.2k
Transcript
今日から使える AWS Step Functions 小技集 山口 正徳 / Masanori YAMAGUCHI
JAWS-UG 茨城 #9 1周年だよ!水戸に集合だぁ! #jawsugibaraki
山口 正徳 フォージビジョン株式会社 JAWS-UG千葉支部 グローバル認定/表彰 ・AWS Community HERO ・AWS Ambassador
・APJ AWS Community Leaders Award 2回受賞(2022、2024) ・AWS Gold Jacket Club 日本国内認定 ・AWS Samurai ・Japan AWS Top Engineer 2019 – 2023, 2025 ・APN ALL AWS Certifications Engineers 2023 – 2024 好きなAWSサービス: Step Functions, ECS Fargate
None
4 Step Functions と 私
山口 正徳 JAWS-UG千葉支部 ステートマシン内でLambda使わない分科会所属 目標・使命 「この世のステーマシンから無駄なLambdaを排除 すること」
AWS re:Inforce 2025 も Step Functions 活用で登壇 • EC2インスタンスが侵害を受けた場合 のセキュリティインシデント対応に
ついて解説しました。 • 解説した手順を自動対応する AWS Step Functions のステートマシンを 開発し公開しました。 re:Inforce 2025 COM324 YouTubeで検索すると アーカイブ動画があります。
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 「封じ込め」の手順が紹介されているドキュメント AWS Well-Architected Framework - Security Pillar https:// docs.aws.amazon.com/ja_jp/wellarchitected/latest/security-pillar/operations.html AWS Security Incident Response User Guide https://docs.aws.amazon.com/ja_jp/security-ir/latest/userguide/containment.html AWS Prescriptive Guidance https://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/automate-incident-response-and-forensics.html AWS Security Incident Response Technical Guide https://docs.aws.amazon.com/ja_jp/whitepapers/latest/aws-security-incident-response-guide/infrastructure-domain-incidents.html AMS Advanced User Guide https://docs.aws.amazon.com/ja_jp/managedservices/latest/userguide/sir-contain.html
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 「収集」の手順が紹介されているドキュメント AWS Well-Architected Framework - Security Pillar https://docs.aws.amazon.com/ja_jp/wellarchitected/latest/security-pillar/operations.html AWS Security Incident Response User Guide https://docs.aws.amazon.com/ja_jp/security-ir/latest/userguide/operations.html https://docs.aws.amazon.com/ja_jp/security-ir/latest/userguide/capture-backups-and-snapshots.html https://docs.aws.amazon.com/ja_jp/security-ir/latest/userguide/appendix-b-incident-response-resources.html#forensic-resources https://docs.aws.amazon.com/ja_jp/security-ir/latest/userguide/collect-relevant-artifacts.html AWS Prescriptive Guidance https://docs.aws.amazon.com/ja_jp/prescriptive-guidance/latest/patterns/automate-incident-response-and-forensics.html
© 2025, Amazon Web Services, Inc. or its affiliates. All
rights reserved. 「収集」の手順が紹介されているドキュメント (続き) AWS Security Incident Response Technical Guide https://docs.aws.amazon.com/ja_jp/whitepapers/latest/aws-security-incident-response-guide/infrastructure-domain-incidents.html https://docs.aws.amazon.com/ja_jp/whitepapers/latest/aws-security-incident-response-guide/capturing-volatile-data.html https://docs.aws.amazon.com/ja_jp/whitepapers/latest/aws-security-incident-response-guide/using-aws-systems-manager.html https://docs.aws.amazon.com/ja_jp/whitepapers/latest/aws-security-incident-response-guide/automating-the-capture.html AMS Advanced User Guide https://docs.aws.amazon.com/ja_jp/managedservices/latest/userguide/sir-contain.html
AWS re:Inforce 2025 も Step Functions 活用で登壇
11 Step Functions 小技 初級編 #jawsugibaraki
12 Step Functions では、各ステート(タスク)の出力を次のステートの入力データとして 自動的に引き継ぐことが可能ですが、データ構造が深くなるとそのままでは扱いづらくなります。 そこで便利なのが Parameters と ResultPathです。 ・
Parameters: タスク(SDK/API)に渡すインプットで出力データを絞り込む ・ ResultPath: タスクの出力を格納する先を指定し、後続タスクで取り扱いやすくする 入力・出力の整理をする「Parameters」と「ResultPath」 "GetInstanceInfo": { "Type": "Task", "Resource": "arn:aws:states:::aws- sdk:ec2:describeInstances", "Parameters": { "InstanceIds.$": "$.instanceId" }, "ResultPath": "$.ec2" } Sdk:ec2:describeInstances に渡す InstanceIds を指定 出力を $.ec2 に格納 #jawsugibaraki
13 タスクの実行結果にもとづき、処理を分岐させる場合に Choice ステートを利用することで簡単に 条件分岐を指定することが可能です。ポイントは、比較対象を JSONPath で指定することと 明確なデフォルト遷移を設定することです。 JSON PATHをシンプルにすることで扱いやすくなるので
ResultPathが役立ちます。 ステートで条件分岐を実現する「Choise」 "CheckStatus": { "Type": "Choice", "Choices": [ { "Variable": "$.status", "StringEquals": "SUCCESS", "Next": "NotifySuccess" } ], "Default": "NotifyFailure" } $.status の値が SUCCESS の場合は、 NotifySuccess ステートに遷移 どの条件にも一致しない場合は、 NotifyFailure ステートに遷移 #jawsugibaraki
14 Passステートを使えばLambdaを使わずにダミーデータを挿入することができます。 Choiceステートを使った条件分岐のテストを行いたいときに便利です。デバッグにもよく使います。 実際のAPI呼び出しをせずに、Choice条件($.status == "FAILED"など)の動作確認が可能です。 使った Pass ステートの定義は Notion
などに保管しておくのがおすすめです。 ステートマシンをエンハンスする時のデバッグに再利用できるので効率を落とさずに開発できます。 「Pass」を使った固定値や分岐テスト用のダミーデータ挿入 "InjectTestData": { "Type": "Pass", "Result": { “status”: “FAILED”, "error_code": 503 }, "Next": "CheckStatus" } status の値に FAILED を挿入 #jawsugibaraki
15 Step Functions 小技 中級編 #jawsugibaraki
16 エラー処理では単純なRetryやCatchだけではなく、エラーごとに異なる再試行ポリシーや分岐処理を 定義できます。特に、States.Timeout / Lambda.ServiceException / States.TaskFailed を 分けて扱うのが本番環境では重要です。 エラー分類にもとづいたフォールバック制御
”CallLambda": { "Type": "Task", "Resource": "arn:aws:states:::lambda:invoke", "Retry": [ { "ErrorEquals": ["States.Timeout"], "IntervalSeconds": 3, "MaxAttempts": 2, "BackoffRate": 1.5 } ], "Catch": [ { "ErrorEquals": ["Lambda.ServiceException", "States.TaskFailed"], "Next": "FallbackPath" } ], "End": true } エラーが Timeout だった場合は、一時的な エラーの可能性を考えて再実行を指定 Exponential Backoff も係数で制御できる Lambdaの例外エラー、タスク実行失敗の 場合はフォールバック処理へ遷移 #jawsugibaraki
17 ステートの実行結果が Raw データで返却される場合、ステートマシンの Output データでは取り扱いが極端に 難しくなります。(JSONPath で参照先を指定できないため) こんな時、Lambdaでjson.loads()を使ってパースしたくなりますが、States.StringToJson()を使えばJSON オブジェクトへ変換することができます。
昔、AWS Top Engineers の競技大会でも States.StringToJson() の知識を問う課題がありました。 組み込み関数を覚えておくと AWS Jam などでも役立つかも。 RawデータからJSONへのデータ変換 "ParseText": { "Type": "Pass", "Parameters": { "Parsed.$": "States.StringToJson($.rawText)" }, "ResultPath": "$.data", "Next": "NextState" } $.rawText を JSONオブジェクトに変換 #jawsugibaraki
18 rawText RawデータからJSONへのデータ変換(つづき) "rawText": "{\"user\":\”kobayashi\",\"age\":36}" States.StringToJson()で変換後 "Parsed": { "user": ”kobayashi",
"age": 36 } { "rawText": "{\"user\":\”kobayashi\",\"age\":36}", "data": { "Parsed": { "user": ”kobayashi", "age": 36 } } } 最終的な状態($.dataへの出力) #jawsugibaraki
19 Step Functions 小技 上級編 #jawsugibaraki
20 ResultSelector でAPIレスポンスを整形して Output に渡す AWS SDK(API) は、Step Functions での利用を前提としているものではないため、レスポンスが深く
Choice や Map における取り扱いが複雑になります。 ResultSelector を使うと、レスポンスを“必要最小限の構造”に整理して Output に渡せるため、 後続ステートでの取り扱いをシンプルにすることができます。 "DescribeInstance": { "Type": "Task", "Resource": "arn:aws:states:::aws-sdk:ec2:describeInstances", "Parameters": { "InstanceIds.$": "$.instanceId" }, "ResultSelector": { "InstanceId.$": "$.Reservations[0].Instances[0].InstanceId", "State.$": "$.Reservations[0].Instances[0].State.Name", "Type.$": "$.Reservations[0].Instances[0].InstanceType", "Tags.$": "$.Reservations[0].Instances[0].Tags" }, "ResultPath": "$.instance", "Next": "NextTask" } ec2:describeInstances のレスポンスから 必要な値を抽出し、最小の JSONPath に 値を代入して整理 インスタンスIDは、$.instance.InstanceId で 取り出せるため、後続ステートのParameter 記述をシンプルできる #jawsugibaraki
21 Payload Templateで「Lambda相当の文字列生成」をASL内だけで完結 ASLで拡張された PayloadTemplate を使うことで、行数の多いメッセージやSlack通知用のテンプレート メッセージ作成を Lambda を使わずにステートマシン内で生成することができます。 JSONata
でも実現できますが、PayloadTemplate は JSONPath で明示指定されたフィールドのみにて 利用可能なため、可読性が高く保守しやすいというメリットがあります。 "MakeMessage_PayloadTemplate": { "Type": "Pass", "Parameters": { "PayloadTemplate": { "Message": "States.Format('{} scored {} points!', $.name, $.score)" } }, "ResultPath": "$.result", "Next": "NextState" } “PayloadTemplate” は 明示指定した フィールドの中で使われ、JSONPath ($.name)および($.score)を参照できる #jawsugibaraki
22 Payload Templateで「Lambda相当の文字列生成」をASL内だけで完結 (JSONataの場合) "MakeMessage_JSONata": { "Type": "Pass", "Parameters": {
"Message": "${$.name & ' scored ' & $.score & ' points!'}" }, "ResultPath": "$.result", "Next": "NextState" } ${ ... } の中は JSONata式 として評価される すべての文字列リテラル(キーや値)は、自動的に JSONataとして解釈されるため PayloadTemplate のように明示的な宣言は不要 { "result": { "Message": "Alice scored 95 points!" } } いずれも ResultPath で出力される Output は下記になる #jawsugibaraki
23 さいごに #jawsugibaraki
24 AWS re:Invent 2025 会場でセキュリティ拡張パック日本語版配布予定 AWS BuilderCards セキュリティ拡張パック、 Builder‘s Galore拡張パック、それぞれ日本語版
の配布を予定しています。 場所: Caesar’s Forum(1階) 11月30日(日曜日) 午前10時 – 午後6時 12月1日(月曜日) 午前9時 – 午後5時 12月2日(火曜日) 午前9時 – 午後5時 12月3日(水曜日) 午前9時 – 午後5時 12月4日(木曜日) 午前9時 – 午後4時 日本人のスタッフもいるようですので英語ができなくて も大丈夫です。 日曜日の午後は私もCaesar’s Forumを歩いてい ると思いますので、現地参加する方は声をかけてくれ ると嬉しいです。
25 BuilderCardsブース ベネチアン方面
- 26 - ご清聴ありがとうございました。 #jawsugibaraki