与输入参数平行的aws步进功能

问题描述

我正在尝试使用AWS步骤功能来创建并行的执行分支。 并行分支之一开始另一步函数调用,如何将输入从该并行分支传递给下一步函数执行

{
  "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
          }
        }
      }
    ]
   }
  }
}

另一步功能学习路径

{

        "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
                }
           }
}

解决方法

您可以使用Input将输出从一个SFN传递到另一个:

第一个SFN(将称为第二个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
    }
  }
}

第二个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
    }
  }
}

第一个SFN的执行

enter image description here

第二次SFN的处决

enter image description here

说明 Lambda test-lambda返回:

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

哪个存储在"ResultPath": "$.to_pass"变量中的to_pass中。我将相同的输出传递给下一个状态机 MyStateMachine2 ,该操作由

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

在下一个状态机的执行中,您会看到相同的数据作为输入被第一个Lambda创建。

您可以详细了解here