aws-step-functions

In an AWS Step function is there a good way to execute a subset of steps based on an input list?


I'm new to AWS Step Functions, and I'm looking to create a step function with the following functionality: I have a lambda that takes in a JSON payload, for example

{
"ExecutionType":"A"
}

This "ExecutionType" can be either A, B, or C, and the lambda will do something different for each type. I want to input a JSON payload with a list at the start of my step function, for example [A,B], and the step function will then invoke this lambda once with the payload for ExecutionType A and once with the payload for ExecutionType B. I'm not sure how to implement this functionality though with the examples I'm seeing online.

To my understanding so far, I would want to make 3 invoke lambda states to invoke the same lambda with each different payload. But when I think about triggering these states, from looking online I only see the Choice step which, to my understanding, would only allow me to move to lambda state A, B, OR C. Meanwhile a Parallel step would require me to execute all 3. Is the functionality I'm looking for possible in an easy way in Step Functions?


Solution

  • This appears to be a good fit for the Map State. Below is an example.

    enter image description here

    {
      "StartAt": "Map",
      "States": {
        "Map": {
          "Type": "Map",
          "ItemProcessor": {
            "ProcessorConfig": {
              "Mode": "INLINE"
            },
            "StartAt": "Lambda Invoke",
            "States": {
              "Lambda Invoke": {
                "Type": "Task",
                "Resource": "arn:aws:states:::lambda:invoke",
                "OutputPath": "$.Payload",
                "Parameters": {
                  "FunctionName": "arn:aws:lambda:us-west-2:123456789101:function:myFunctionName",
                  "Payload": {
                    "ExecutionType.$": "$"
                  }
                },
                "Retry": [
                  {
                    "ErrorEquals": [
                      "States.ALL"
                    ],
                    "IntervalSeconds": 1,
                    "MaxAttempts": 3,
                    "BackoffRate": 2
                  }
                ],
                "End": true
              }
            }
          },
          "End": true,
          "ItemsPath": "$.executionTypes"
        }
      }
    }