4

dataflow

It can not be described with Parallel State in AWS Step Function.

B and C should be in parallel.

C sends messages to both D and E.

D and E should be in parallel.

Tauta
  • 907
  • 1
  • 8
  • 12

3 Answers3

2

enter image description here

{
    "StartAt": "A",
    "States": {
        "A": {
            "Type": "Pass",
            "Next": "Parallel State 1"
        },
        "Parallel State 1": {
            "Type": "Parallel",
            "Branches": [{
                    "StartAt": "B",
                    "States": {
                        "B": {
                            "Type": "Pass",
                            "End": true
                        }
                    }
                },
                {
                    "StartAt": "C",
                    "States": {
                        "C": {
                            "Type": "Pass",
                            "End": true
                        }
                    }
                }
            ],
            "Next": "Parallel State 2"
        },
        "Parallel State 2": {
            "Type": "Parallel",
            "Branches": [{
                    "StartAt": "D",
                    "States": {
                        "D": {
                            "Type": "Pass",
                            "End": true
                        }
                    }
                },
                {
                    "StartAt": "E",
                    "States": {
                        "E": {
                            "Type": "Pass",
                            "End": true
                        }
                    }
                }
            ],
            "Next": "F"
        },
        "F": {
            "Type": "Pass",
            "End": true
        }
    }
}
Horatiu Jeflea
  • 7,256
  • 6
  • 38
  • 67
0

Answer is No , inside step function no state can set multiple states (invokes both successors)to its Next task. As per AWS step function cannot start State Machine as StartAt by providing multiple State names.

You can tweak your logic and use The Parallel state and achive same ,If you share your usecase may be help to solve problems.

A Parallel state provides each branch with a copy of its own input data (subject to modification by the InputPath field). It generates output that is an array with one element for each branch, containing the output from that branch.

Example of state function

enter image description here

{
  "Comment": "An example of the Amazon States Language using a choice state.",
  "StartAt": "FirstState",
  "States": {
    "FirstState": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:REGION:ACCOUNT_ID:function:FUNCTION_NAME",
      "Next": "ChoiceState"
    },
    "ChoiceState": {
      "Type" : "Choice",
      "Choices": [
        {
          "Variable": "$.foo",
          "NumericEquals": 1,
          "Next": "FirstMatchState"
        },
        {
          "Variable": "$.foo",
          "NumericEquals": 2,
          "Next": "SecondMatchState"
        }
      ],
      "Default": "DefaultState"
    },

    "FirstMatchState": {
      "Type" : "Task",
      "Resource": "arn:aws:lambda:REGION:ACCOUNT_ID:function:OnFirstMatch",
      "Next": "NextState"
    },

    "SecondMatchState": {
      "Type" : "Task",
      "Resource": "arn:aws:lambda:REGION:ACCOUNT_ID:function:OnSecondMatch",
      "Next": "NextState"
    },

    "DefaultState": {
      "Type": "Fail",
      "Error": "DefaultStateError",
      "Cause": "No Matches!"
    },

    "NextState": {
      "Type": "Task",
      "Resource": "arn:aws:lambda:REGION:ACCOUNT_ID:function:FUNCTION_NAME",
      "End": true
    }
  }
}
vaquar khan
  • 10,864
  • 5
  • 72
  • 96
0

As I answered in How to simplify complex parallel branch interdependencies for Step Functions, what you asked is better to be modeled as DAG but not state machine.

Depends on your use case, you might be able to workaround it (just as @horatiu-jeflea 's answer), but it's a workaround (not the straightforward way) anyway.

wanghq
  • 1,336
  • 9
  • 17