datahack
datahack

Reputation: 659

AWS Nested Step Functions

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?

Upvotes: 2

Views: 1253

Answers (3)

user21363611
user21363611

Reputation: 1

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

Upvotes: 0

Nhu Trinh
Nhu Trinh

Reputation: 13956

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

Upvotes: 0

Horatiu Jeflea
Horatiu Jeflea

Reputation: 7404

You could

  1. Unescape the string in the Lambda that produces it
  2. Have a separate lambda which only escapes (your suggestion)
  3. 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.

Upvotes: 1

Related Questions