In AWS step functions is it possible to have something like:
"ProcessOutput": {
"Type": "Pass",
"Result": {
"username.$": "$.Payload?.username" // optional result
},
"End": true
}
where username.$
is optional?
No. Step Functions path syntax does not support optional paths. The Step Functions execution will fail if $.Payload.username
is not defined.
Note that in any case, the Pass state's Result
key only accepts static values, not JSONPath references. The Parameters
field accepts path substitutions, but just not optional ones.
What alternatives do you have to handle an optional field? One option is a Lambda task. A second option is a Choice state with an IsPresent
conditional check on the optional field. If the field is not present, set a default or otherwise handle the case.