Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Combining AWS step function task and map outputs in to one array

I have a task state that outputs the following:

"batch": {
    "batch": "size",
    "currentTimestamp": 1596205376
  },

and a map state out outputs an array:

"batch": [
    {
      "batch": "product-batch-0",
      "currentTimestamp": 1596205376
    },
    {
      "batch": "product-batch-1",
      "currentTimestamp": 1596205376
    }
]

I would like to combine them so that the input to the state that follows the map state is this:

  "batch": [
    {
    "batch": "Size",
    "currentTimestamp": 1596205376
    },
    {
      "batch": "product-batch-22",
      "currentTimestamp": 1596205376
    },
    {
      "batch": "product-batch-8",
      "currentTimestamp": 1596205376
    }
]

Is this possible using the input/output processing available in aws step functions? I want to have them contained in one array so they can be processed together in an additional map state later in the state machine.

like image 457
RMMD12 Avatar asked Jun 10 '26 00:06

RMMD12


2 Answers

It is possible. try this.

  • ASL Definition
{
  "StartAt": "getArrayOfArray",
  "States": {
    "getArrayOfArray": {
      "Type": "Pass",
      "Parameters": {
        "arrayOfArray.$": "States.Array($.array, States.Array($.appendant))"
      },
      "Next": "mergeArray"
    },
    "mergeArray": {
      "Type": "Pass",
      "Parameters": {
        "mergedArray.$": "$.arrayOfArray[*][*]"
      },
      "End": true
    }
  }
}
  • input
{
  "array": [
    {
      "batch": "product-batch-0",
      "currentTimestamp": 1596205376
    },
    {
      "batch": "product-batch-1",
      "currentTimestamp": 1596205376
    }
  ],
  "appendant": {
    "batch": "size",
    "currentTimestamp": 1596205376
  }
}
  • output
{
  "mergedArray": [
    {
      "batch": "product-batch-0",
      "currentTimestamp": 1596205376
    },
    {
      "batch": "product-batch-1",
      "currentTimestamp": 1596205376
    },
    {
      "batch": "size",
      "currentTimestamp": 1596205376
    }
  ]
}
like image 160
若槻龍太 Avatar answered Jun 11 '26 14:06

若槻龍太


You should use another Lambda function to merge the input and output because the step functions output feature cannot append the result into an array or merge the input and output as an array.

[1] : https://docs.aws.amazon.com/step-functions/latest/dg/input-output-resultpath.html#input-output-resultpath-append

like image 24
Lamanus Avatar answered Jun 11 '26 14:06

Lamanus