aws-step-functions

How to return empty result path in AWS Step Function


I have a stepfunction with a map state that does some work. Each iteration figures out if it actually does need to do the work or not. If it doesn't need to do work it ends in a noop. If it needs to do work it does the work.

I want to collect the results at the end, however I don't want any results from the noop. You can't set the resultpath to $ or null, since it just uses the input. Is it possible to return an "empty" from a noop state? Or not collect the result there?

I tried something like JsonPath.DISCARD but couldn't get it working in cloudformation. $ or null just pass in the original input which I don't want since the output would become giant.

I could also just have a lambda instead of a NOOP but I wanted to see if there was a way to do it with a noop first.


Solution

  • Unfortunately, there is no built-in way to discard the result entirely or return an "empty" result from a noop state directly within Step Functions(THAT I KNOW). However, as you suggested, you can use a Lambda function as a workaround to achieve this behavior.

    1)Define a Lambda function that takes the input and returns an empty object {} if it's a noop, or performs the required work otherwise.

    2)Configure your Step Functions state machine to invoke this Lambda function instead of using a noop state directly.