LoginSignup
7
0

More than 1 year has passed since last update.

Step Functions のパラメータで配列を扱いたい

Posted at

組み込み関数の States.Array を使う

States.Array
This intrinsic takes zero or more arguments. The interpreter returns a JSON array containing the Values of the arguments, in the order provided. For example, given the following input:

{
  "Id": 123456
}

You could use

"BuildId.$": "States.Array($.Id)"

Which would return “BuildId”: [123456]

Example

AWS SDK 統合で EC2 の StartInstances を call する場合場合、API パラメータは以下のような形式です。

{
  "InstanceIds": [
    "MyData"
  ]
}

image.png

ステートマシン実行時の Input で以下の入力を受け取る前提を考えたとき、

{
    "InstanceId": "i-xxxxxxxxxxxxxxxxxxx"
}

API パラメータで以下のような設定でステートマシンを保存しようとするとエラーになります。

{
  "InstanceIds.$": [
    "$.InstanceId"
  ]
}

image.png

The value for the field 'InstanceIds.$' must be a STRING that contains a JSONPath but was an ARRAY

このようなケースで組み込み関数の States.Array を使用できます。

{
  "InstanceIds.$": "States.Array($.InstanceId)"
}

結果として以下が返されるため、StartInsntaces を正常に実行できます。

{
  "InstanceIds":[
    "i-xxxxxxxxxxxxxxxxxxx"
  ]
}

image.png

簡単ですが、以上です。

7
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
0