Search code examples
amazon-web-servicesaws-cdkaws-step-functions

How to add optional variable in Step Function in typescript


In the following code, if documentDetails is available in payload of the step function for step Read, then only documentDetails variable be considered, otherwise it shouldn't be. documentDetails is optional and it may or may not be there in payload.

const readStep = new tasks.LambdaInvoke(this, 'Read', {
            lambdaFunction: stepfLambda,
            resultSelector: {
                "s3Url.$": "$.Payload.s3Url",
                "documentDetails.$": // present only if documentDetails is present in Payload
            },
            resultPath: '$.stepEventMetaData'
        });

What is the correct syntax for the same?


Solution

  • resultSelector cannot apply conditional logic. Your best option is to have stepfLambda return the output in the desired shape.