I have two step functions that run in third one(nested step functions). When first one finishes it creates JSON with a lot of key value information. I want to use this JSON as is in next step function. Currently, output from first step function is escaped string. Is there any nice way to do this, without executing lambda to parse this escaped json string?
3 Answers
You could
- Unescape the string in the Lambda that produces it
- Have a separate lambda which only escapes (your suggestion)
- Escape it in the lambda that consumes it
I would go with 2. considering single responsibility principle, but if you want to avoid another lambda invocation, go with 1. or 3.
Comments
You can use :2 option when you invoke second step function. That will return a json instead of escape string.
{
"Type":"Task",
"Resource":"arn:aws:states:::states:startExecution.sync:2",
"Parameters":{
"Input":{
"Comment": "Your input goes here",
"AWS_STEP_FUNCTIONS_STARTED_BY_EXECUTION_ID.$": "$$.Execution.Id"
},
"StateMachineArn":"arn:aws:states:us-east-1:123456789012:stateMachine:NestedStateMachine",
"Name":"ExecutionName"
},
"End":true
}
Source: https://docs.aws.amazon.com/step-functions/latest/dg/connect-stepfunctions.html
Comments
We can remove the escape string by converting the output of your step in ResultSelector using "States.StringToJson($), where $ is your output JSON.
This removes escape chars and returns the JSON object.
Hope this helps. For details refer to the Intrinsic Functions