Search code examples
amazon-web-servicesyamlaws-cloudformationaws-step-functions

Include map input to the aws step function


Currently I have a yaml file which includes different states in the Step function that runs different checks and returns pass or fail output

code Snippet:


Comment: Check all steps
StartAt: Check A

States:
  Check A:
    Comment: Verifies that A is done
    Resource: "arn:aws:lambda:us-east-1:123456789012:function:checkA",
    Next: Check B

  Check B:
    Comment:Verifies that B is done
      Resource: "arn:aws:lambda:us-east-1:123456789012:function:checkB"
    Next: Check C

  Check C:
     Comment:Verifies that C is done
      Resource: "arn:aws:lambda:us-east-1:123456789012:function:checkC"
    ResultPath: "$.ValidatedResults"
    End: true


How can I modify this step function to accept an input map such that it only executes those States with boolean true

"OnlyVerify": {
    "Check A": true,
    "Check B": false
    "Check C": true
   
}

And if OnlyVerify map is not specified as input to the Step function, it should run all the Checks.(True for all checks by default)

Expected Output

{
"OnlyVerify": {
    "Check A": true,
    "Check B": false
    "Check C": true
   
},
"ValidatedResults": {
    "Check A": PASS,
    "Check C": PASS
}


}

Appreciate any guidance here


Solution

  • I would suggest playing with the logic a bit in the Workflow Studio, but something like this should get you most of the way there:

    example workflow

    If the lambda function used to do the checking can be refactored to handle any of [A, B, C, ...] then that would enable making the step function definition much "cleaner" by leveraging a Map State, rather than a parallel state.