aws 步进函数与输入参数并行
aws step function parallel with input parameters
我正在尝试使用 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
}
}
}
]
}
}
}
另一个stepfunctionarnpath :
{
"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 的执行
第二次执行 SFN
说明
Lambda test-lambda
正在返回:
{
"user": "Whosebug",
"id": "100"
}
存储在 "ResultPath": "$.to_pass"
这里的 to_pass
变量中。我将相同的输出传递给下一个状态机 MyStateMachine2,这是由
完成的
"Input": {
"Comment.$": "$"
}
在下一个状态机的执行中,您会看到接收到与第一个 Lambda 创建的输入相同的数据。
您可以阅读更多相关信息 here。
我正在尝试使用 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
}
}
}
]
}
}
}
另一个stepfunctionarnpath :
{
"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 的执行
第二次执行 SFN
说明
Lambda test-lambda
正在返回:
{
"user": "Whosebug",
"id": "100"
}
存储在 "ResultPath": "$.to_pass"
这里的 to_pass
变量中。我将相同的输出传递给下一个状态机 MyStateMachine2,这是由
"Input": {
"Comment.$": "$"
}
在下一个状态机的执行中,您会看到接收到与第一个 Lambda 创建的输入相同的数据。
您可以阅读更多相关信息 here。