AWS Step Functions(AWS のワークフロー自動化サービス)のステートマシン(処理の流れを状態遷移で表現したもの)を、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.
AWS Step Functions は Amazon States Language (ASL) を使用して、ステートマシンを JSON 形式で定義します。AWS Step Functions を利用することで、ワークフロー(ステートマシンとも呼ばれる)を作成し、分散アプリケーションの構築、プロセスの自動化、マイクロサービスのオーケストレーション、データおよび機械学習パイプラインの構築が可能です。
このスキルは ASL でステートマシンを記述するための包括的なガイダンスを提供し、以下の内容をカバーします:
$states 予約変数Assign を使ったワークフロー変数ユーザーが取り組んでいる内容に応じて、適切な参照ファイルを読み込んでください:
| 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 を省略した場合のデフォルトです。既存のステートマシンを移行する必要はありません。
"QueryLanguage": "JSONata" を設定するOutput は最小限に保つ — 現在のステートの直後のステートが必要とするデータのみを含めるOutput を介してデータを引き回すのではなく、Assign を使って保存する$states.input を使用するAssign と Output は並行して評価されるため、Assign で設定した変数は同一ステートの Output では利用できない$data.nonExistentField のように未定義フィールドを参照すると States.QueryEvaluationError がスローされる$states.context.Execution.Input を使用する.asl.json 拡張子で保存するarn:aws:states:::lambda:invoke)を優先して使用するStates.QueryEvaluationError — JSONata 式の実行に失敗。型エラー、未定義フィールド、範囲外の値がないか確認する。$ や $$ を使用している — 代わりに $states.input を使用する。{% %} デリミタで囲み忘れている — デリミタがないと文字列リテラルとして扱われる。Assign で設定した変数を同一ステートの Output で参照しようとしている — 新しい値は次のステートからのみ有効になる。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:
$states reserved variableAssignLoad the appropriate reference file based on what the user is working on:
| 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.
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.
"QueryLanguage": "JSONata" at the top level for new state machines unless the user wants to use JSONPathOutput minimal — only include what the state immediately after the current state needsAssign to store variables needed in later states instead of threading it through Output$states.input to reference original state inputAssign and Output are evaluated in parallel — variable assignments in Assign are NOT available in Output of the same state$data.nonExistentField throws States.QueryEvaluationError$states.context.Execution.Input to access the original workflow input from any state.asl.json extension when working outside the consolearn:aws:states:::lambda:invoke) over the SDK integrationStates.QueryEvaluationError — JSONata expression failed. Check for type errors, undefined fields, or out-of-range values.$ or $$ at the top level of a JSONata expression — use $states.input instead.{% %} delimiters around JSONata expressions — the string will be treated as a literal.Assign and expecting them in Output of the same state — new values only take effect in the next state.原文・著作権は Anthropic および各プラグイン作者に帰属します。日本語訳は Claude API による自動翻訳です。