简体   繁体   中英

aws step function parallel with input parameters

I am trying to use AWS step functions to create parallel branches of execution. One of the parallel branches starts another step function invocation, how can we pass input from this parallel branch to next step function execution

{
  "Comment": "Parallel Example.",
  "StartAt": "FunWithMath",
  "States": {
    "FunWithMath": {
    "Type": "Parallel",
    "End": true,
    "Branches": [
      {
        "StartAt": "Add",  /// This receives some json object here input {}
        "States": {
          "Add": {    
            "Type": "Task",  ***//How to pass the received input to the following arn as input?***
            "Resource": ""arn:aws:states:::states:startExecution",
            Parameters: {
                 "StateMachineArn": "anotherstepfunctionarnpath"
                }
            "End": true
          }
        }
      },
      {
        "StartAt": "Subtract",
        "States": {
          "Subtract": {
            "Type": "Task",
            "Resource": "some lambda arn here,
            "End": true
          }
        }
      }
    ]
   }
  }
}

anotherstepfunctionarnpath :

{

        "Comment": "Second state machine",
        "StartAt": "stage1",
         "Resource": "arn:aws:states:::glue:startJobRun.sync",
         "Parameters":{
             "Arguments":{
                 "Variable1" :"???" / how to access the value of the input passed to here
                }
           }
}

You can use Input to pass output from one SFN to other one:

First SFN(It will call second SFN)

{
  "Comment": "My first SFN",
  "StartAt": "First SFN",
  "States": {
    "First SFN": {
      "Type": "Task",
      "ResultPath": "$.to_pass",
      "Resource": "arn:aws:lambda:us-east-1:807278658150:function:test-lambda",
      "Next": "Trigger Next SFN"
    },
    "Trigger Next SFN": {
      "Type": "Task",
      "Resource": "arn:aws:states:::states:startExecution",
      "Parameters": {
        "Input": {
          "Comment.$": "$"
        },
        "StateMachineArn": "arn:aws:states:us-east-1:807278658150:stateMachine:MyStateMachine2"
      },
      "End": true
    }
  }
}

Second SFN (MyStateMachine2)

{
  "Comment": "A Hello World example of the Amazon States Language using Pass states",
  "StartAt": "Hello",
  "States": {
    "Hello": {
      "Type": "Pass",
      "Result": "Hello",
      "Next": "World"
    },
    "World": {
      "Type": "Pass",
      "Result": "World",
      "End": true
    }
  }
}

First SFN's Execution

在此处输入图像描述

Second SFN's Execution

在此处输入图像描述

Explanation The Lambda test-lambda is returning:

{
  "user": "stackoverflow",
  "id": "100"
}

Which is stored in "ResultPath": "$.to_pass" here in to_pass variable. I am passing the same output to next state machine MyStateMachine2 which is done by

"Input": {
   "Comment.$": "$"
}

In the next State Machine's execution you see that same data is received as input which was created by first Lambda.

You can read more about it here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM