Step Functions の Paralell ステートの出力の順序は保証されているのか教えてください

2024.05.01

困っていた内容

Step Functions ステートマシンの Paralell ステートの出力の順序について教えてください。
具体的には、Branches で指定した順序が、出力の配列でも保証されるのか知りたいです。

どう対応すればいいの?

Paralell ステートの出力の順序は、Branches 配列で指定した順序に対応しています。

Amazon States Language

The Parallel State passes its input (potentially as filtered by the "InputPath" field) as the input to each branch’s "StartAt" state. It generates a result which is an array with one element for each branch containing the output from that branch. The elements of the output array correspond to the branches in the same order that they appear in the "Branches" array.

補足

RFC 8259 には、JSON オブジェクトは順序付けされていないとの記載があります。

rfc-editor.org/rfc/rfc8259.txt

An object is an unordered collection of zero or more name/value pairs

Step Functions ステートマシンの定義は、JSON ではなく、JSON ベースの言語である Amazon ステートメント言語(以下 ASL)によって記述されます。

Amazon ステートメント言語 - AWS Step Functions

Amazon ステートメント言語は JSON ベースの構造化言語で、ステートマシンおよび作業を実行できる状態のコレクション (Task 状態) の定義、次に移行する状態の決定 (Choice 状態)、エラーによる実行の停止 (Fail 状態) などに使用されます。

そのため、ステートマシンの定義について確認する際は、JSON オブジェクトの仕様の観点ではなく、ASL の観点から確認することを推奨します。
ASL の仕様については、以下のドキュメントをご参照ください。

Amazon States Language

参考資料

AWS Step FunctionsのParallelステートを使って並列実行させる | DevelopersIO
Amazon States Language
rfc-editor.org/rfc/rfc8259.txt
Amazon ステートメント言語 - AWS Step Functions
Amazon States Language