A rather new addition to step functions can easily solve the problem with a single state; however it would most probably require converting each of the states of your current step function from JSONPath to JSONata format.
"Arguments": {
"foo": "{% $exists($states.context.Execution.Input.foo) ? $states.context.Execution.Input.foo : 'bar' %}"
}
$states.input.foo
rather than $states.context.Execution.Input.foo
. However, the latter ensures it's the input you've received once the step function execution commenced and not a variable whose value could potentially have changed during the execution.For further reading: