🔄aws-step-functions
- プラグイン
- aws-serverless
- 引数
- [what workflow are you building?]
- ソース
- GitHub で見る ↗
説明
AWS Step FunctionsのステートマシンをJSONataクエリ言語を使用してワークフローとして構築します。 Amazon States Language(ASL)の構造、ステートタイプ、変数、データ変換、エラーハンドリング、AWSサービスとの統合、およびJSONPathからJSONataクエリ言語へのマイグレーションについて網羅しています。
原文を表示
Build workflows with AWS Step Functions state machines using the JSONata query language. Covers Amazon States Language (ASL) structure, state types, variables, data transformation, error handling, AWS service integration, and migrating from the JSONPath to the JSONata query language.
ユースケース
- ✓ステートマシンをJSONataで構築するとき
- ✓ASLの構造を理解する必要があるとき
- ✓ワークフロー内でデータ変換を行うとき
- ✓JSONPathからJSONataへ移行するとき
- ✓AWSサービスとの統合を設定するとき
本文(日本語訳)
AWS Step Functions
概要
AWS Step Functions は Amazon States Language (ASL) を使用して、ステートマシンを JSON 形式で定義します。AWS Step Functions を利用することで、ワークフロー(ステートマシンとも呼ばれる)を作成し、分散アプリケーションの構築、プロセスの自動化、マイクロサービスのオーケストレーション、データおよび機械学習パイプラインの構築が可能です。
このスキルは ASL でステートマシンを記述するための包括的なガイダンスを提供し、以下の内容をカバーします:
- ASL の構造と JSONata 式の構文
- 利用可能な 8 種類のワークフローステートの詳細
$states予約変数Assignを使ったワークフロー変数- エラーハンドリング
- AWS サービス統合パターン
- データ変換およびアーキテクチャのサンプルコード
- ステートマシンのバリデーションとテスト
- JSONPath から JSONata への移行方法
参照ファイルの読み込みタイミング
ユーザーが取り組んでいる内容に応じて、適切な参照ファイルを読み込んでください:
- ASL の構造・ステートタイプ・Task・Pass・Choice・Wait・Succeed・Fail・Parallel・Map → references/asl-state-types.md を参照
- エラーハンドリング・トラブルシューティング・Retry・Catch・フォールバック・エラーコード・States.Timeout・States.ALL → references/error-handling.md を参照
- サービス統合・Lambda invoke・DynamoDB・SNS・SQS・SDK 統合・Resource ARN・sync・async → references/service-integrations.md を参照
- JSONPath から JSONata への移行・migration・InputPath・Parameters・ResultSelector・ResultPath・OutputPath・組み込み関数・Iterator・payload テンプレート → references/migrating-from-jsonpath-to-jsonata.md を参照
- バリデーション・リンティング・テスト・TestState・モック・ユニットテスト・inspection level・DEBUG・TRACE・ステートの検証・単体テスト → references/validation-and-testing.md を参照
- アーキテクチャパターン・サンプル・ポーリング・saga・補償処理・scatter-gather・セマフォ・ロック・human-in-the-loop・エスカレーション・Express から Standard への移行 → references/architecture-patterns.md を参照
- データ変換・JSONata 式・フィルタリング・集計・文字列操作・$reduce・$lookup・$toMillis・$partition・$parse・$hash・$uuid → references/transforming-data.md を参照
- ステートの入出力・$states・Assign・Output・Arguments・変数スコープ・変数の制限・評価順序・ステート間のデータ受け渡し → references/processing-state-inputs-and-outputs.md を参照
- デプロイ・SAM・CloudFormation・IaC・DefinitionSubstitutions・X-Ray トレーシング・ロギング → aws-serverless-deployment スキル または deploy-on-aws プラグイン を参照
クイックリファレンス
Standard ワークフロー vs Express ワークフロー
| Standard | Express | |
|---|---|---|
| 最大実行時間 | 1 年 | 5 分 |
| 実行セマンティクス | Exactly-once(厳密に 1 回) | At-least-once(非同期) / At-most-once(同期) |
| 実行履歴 | 90 日間保持、API 経由でクエリ可能 | CloudWatch Logs のみ |
| 最大スループット | 2,000 実行/秒 | 100,000 実行/秒 |
| 料金モデル | ステート遷移ごと | 実行回数 + 実行時間ごと |
.sync / .waitForTaskToken |
サポートあり | サポートなし |
| 最適なユースケース | 監査可能な非冪等操作 | 高スループットな冪等イベント処理 |
Standard を選択する場合: 決済処理、注文管理、コンプライアンスワークフロー、二重実行が絶対に許されない処理。
Express を選択する場合: IoT データ取り込み、ストリーミング変換、モバイルバックエンド、高スループットで短命な処理。
ステートマシンのクエリ言語の設定
JSONata は ASL においてデータの参照と変換を行うための、モダンかつ推奨される方法です。JSONPath の 5 つの I/O フィールド(InputPath・Parameters・ResultSelector・ResultPath・OutputPath)を、Arguments(入力)と Output の 2 つに置き換えます。
トップレベルで有効化することで、すべてのステートに適用されます:
{ "QueryLanguage": "JSONata", "StartAt": "...", "States": {...} }
または、ステートごとに指定することで JSONPath から段階的に移行できます:
{ "Type": "Task", "QueryLanguage": "JSONata", ... }
JSONPath は引き続きサポートされており、QueryLanguage を省略した場合のデフォルトです。既存のステートマシンを移行する必要はありません。
ベストプラクティス
- 新規ステートマシンでは、ユーザーが JSONPath を希望しない限り、トップレベルに
"QueryLanguage": "JSONata"を設定する Outputは最小限に保つ — 現在のステートの直後のステートが必要とするデータのみを含める- 後続のステートで必要な変数は
Outputを介してデータを引き回すのではなく、Assignを使って保存する - 元のステート入力を参照する際は
$states.inputを使用する - 注意:
AssignとOutputは並行して評価されるため、Assignで設定した変数は同一ステートのOutputでは利用できない - JSONata 式は必ず定義済みの値を返さなければならない —
$data.nonExistentFieldのように未定義フィールドを参照するとStates.QueryEvaluationErrorがスローされる - 任意のステートから元のワークフロー入力にアクセスするには
$states.context.Execution.Inputを使用する - コンソール外で作業する場合、ステートマシンの定義ファイルは
.asl.json拡張子で保存する - SDK 統合よりも最適化された Lambda 統合(
arn:aws:states:::lambda:invoke)を優先して使用する
トラブルシューティング
よくあるエラー
States.QueryEvaluationError— JSONata 式の実行に失敗。型エラー、未定義フィールド、範囲外の値がないか確認する。- 同一ステート内で JSONPath フィールドと JSONata フィールドを混在させている。
- JSONata 式のトップレベルで
$や$$を使用している — 代わりに$states.inputを使用する。 - JSONata 式を
{% %}デリミタで囲み忘れている — デリミタがないと文字列リテラルとして扱われる。 Assignで設定した変数を同一ステートのOutputで参照しようとしている — 新しい値は次のステートからのみ有効になる。- 詳細なトラブルシューティング情報については references/validation-and-testing.md および references/error-handling.md を参照する。
リソース
原文(English)を表示
AWS Step Functions
Overview
AWS Step Functions uses Amazon States Language (ASL) to define state machines as JSON. With AWS Step Functions, you can create workflows, also called State machines, to build distributed applications, automate processes, orchestrate microservices, and create data and machine learning pipelines.
This skill provides comprehensive guidance for writing state machines in ASL, covering:
- ASL structure and JSONata expression syntax
- Details on the eight available workflow states
- The
$statesreserved variable - Workflow variables with
Assign - Error handling
- AWS Service integration patterns
- Example code for data transformation and architecture
- Validation and testing of state machines
- How to migrate from JSONPath to JSONata
When to Load Reference Files
Load the appropriate reference file based on what the user is working on:
- ASL structure, state types, Task, Pass, Choice, Wait, Succeed, Fail, Parallel, Map → see references/asl-state-types.md
- Error handling, troubleshooting, Retry, Catch, fallback, error codes, States.Timeout, States.ALL → see references/error-handling.md
- Service integrations, Lambda invoke, DynamoDB, SNS, SQS, SDK integrations, Resource ARN, sync, async → see references/service-integrations.md
- Migrating from JSONPath to JSONata, migration, JSONPath to JSONata, InputPath, Parameters, ResultSelector, ResultPath, OutputPath, intrinsic functions, Iterator, payload template → see references/migrating-from-jsonpath-to-jsonata.md
- Validation, linting, testing, TestState, test state, mock, mocking, unit test, inspection level, DEBUG, TRACE, validate state, test in isolation → see references/validation-and-testing.md
- Architecture patterns, examples, polling, saga, compensation, scatter-gather, semaphore, lock, human-in-the-loop, escalation, Express to Standard → see references/architecture-patterns.md
- Data transformation, JSONata expressions, filtering, aggregation, string operations, $reduce, $lookup, $toMillis, $partition, $parse, $hash, $uuid → see references/transforming-data.md
- State input/output, $states, Assign, Output, Arguments, variable scope, variable limits, evaluation order, passing data between states → see references/processing-state-inputs-and-outputs.md
- Deployment, SAM, CloudFormation, IaC, DefinitionSubstitutions, X-Ray tracing, logging → see the aws-serverless-deployment skill or deploy-on-aws plugin
Quick Reference
Standard vs Express Workflows
| Standard | Express | |
|---|---|---|
| Max duration | 1 year | 5 minutes |
| Execution semantics | Exactly-once | At-least-once (async) / At-most-once (sync) |
| Execution history | Retained 90 days, queryable via API | CloudWatch Logs only |
| Max throughput | 2,000 exec/sec | 100,000 exec/sec |
| Pricing model | Per state transition | Per execution count + duration |
.sync / .waitForTaskToken |
Supported | Not supported |
| Best for | Auditable, non-idempotent operations | High-volume, idempotent event processing |
Choose Standard for: payment processing, order fulfillment, compliance workflows, anything that must never execute twice.
Choose Express for: IoT data ingestion, streaming transformations, mobile backends, high-throughput short-lived processing.
Setting the State Machine Query Language
JSONata is the modern, preferred way to reference and transform data in ASL. It replaces the five JSONPath I/O fields (InputPath, Parameters, ResultSelector, ResultPath, OutputPath) with just two: Arguments (inputs) and Output.
Enable at the top level to apply to all states:
{ "QueryLanguage": "JSONata", "StartAt": "...", "States": {...} }
Or per-state to migrate from JSONPath incrementally:
{ "Type": "Task", "QueryLanguage": "JSONata", ... }
JSONPath is still supported and is the default if QueryLanguage is omitted — existing state machines do not need to be migrated.
Best Practices
- Set
"QueryLanguage": "JSONata"at the top level for new state machines unless the user wants to use JSONPath - Keep
Outputminimal — only include what the state immediately after the current state needs - Use
Assignto store variables needed in later states instead of threading it through Output - Use
$states.inputto reference original state input - Remember:
AssignandOutputare evaluated in parallel — variable assignments inAssignare NOT available inOutputof the same state - All JSONata expressions must produce a defined value —
$data.nonExistentFieldthrowsStates.QueryEvaluationError - Use
$states.context.Execution.Inputto access the original workflow input from any state - Save state machine definitions with
.asl.jsonextension when working outside the console - Prefer the optimized Lambda integration (
arn:aws:states:::lambda:invoke) over the SDK integration
Troubleshooting
Common Errors
States.QueryEvaluationError— JSONata expression failed. Check for type errors, undefined fields, or out-of-range values.- Mixing JSONPath fields with JSONata fields in the same state.
- Using
$or$$at the top level of a JSONata expression — use$states.inputinstead. - Forgetting
{% %}delimiters around JSONata expressions — the string will be treated as a literal. - Assigning variables in
Assignand expecting them inOutputof the same state — new values only take effect in the next state. - Reference references/validation-and-testing.md and references/error-handling.md for detailed troubleshooting information.
Resources
原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。