简体   繁体   English

AWS Stepfunction 将数据传递给下一个 lambda 而无需所有额外填充

[英]AWS Stepfunction pass data to next lambda without all the extra padding

I have created a state machine with AWD CDK (typescript) and it all works fine.我用 AWD CDK(打字稿)创建了一台 state 机器,一切正常。 It is just the output of Lambda 1 which is the input for Lambda 2, has some sort of state machine padding which I am not interested in.它只是 Lambda 1 的 output,它是 Lambda 2 的输入,具有某种我不感兴趣的 state 机器填充。

Definition of state machine: state机器的定义:

{
  "StartAt": "",
  "States": {
    "...applicationPdf": {
      "Next": "...setApplicationProcessed",
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Parameters": {
        "FunctionName": "...applicationPdf",
        "Payload.$": "$"
      }
    },
    "...setApplicationProcessed": {
      "Next": "Done",
      "Type": "Task",
      "Resource": "arn:aws:states:::lambda:invoke",
      "Parameters": {
        "...applicationPdf",
        "Payload.$": "$"
      }
    },
    "Done": {
      "Type": "Succeed"
    }
  }
}

Output of Lambda1 (applicationPdf): Lambda1的Output(applicationPdf):

{
  "ExecutedVersion": "$LATEST",
  "Payload": {
    ...
  },
  "SdkHttpMetadata": {
    "AllHttpHeaders": {
      ...
    },
    "HttpHeaders": {
       ....
    },
    "HttpStatusCode": 200
  },
  "SdkResponseMetadata": {
     ....
  },
  "StatusCode": 200
}

So I am only interested in Payload , not all the other stuff.所以我只对Payload感兴趣,而不是所有其他的东西。 The reason I want to do is that is I want to run the 2nd lambda separately I just want the Event going into the Lambda, to be the Payload object, not the the object with ExecutedVersion etc .我想做的原因是我想单独运行第二个 lambda 我只希望事件进入 Lambda,成为有效负载 object,而不是带有ExecutedVersion etc的 object。

Does anyone know how to do this?有谁知道如何做到这一点? I will have a look at the Parameters option of the definition, maybe the answer lies there.我会看看定义的Parameters选项,也许答案就在那里。

Thanks for your question and for your interest in Step Functions.感谢您提出问题并感谢您对 Step Functions 的关注。

The ResultSelector and OutputPath fields can be used to manipulate the output of a state, which can be particularly helpful when a state outputs values which you do not need access to in subsequent states. ResultSelectorOutputPath字段可用于操作 state 的 output,这在 state 输出您不需要在后续状态中访问的值时特别有用。 The difference between them is that ResultSelector is applied before the state's ResultPath is applied, while OutputPath is applied after it.它们之间的区别在于,ResultSelector 在应用状态的 ResultPath 之前应用,而 OutputPath 在它之后应用。

As you noted, you can use OutputPath to filter out any unwanted metadata before being passed on to the next state.如您所述,您可以使用 OutputPath 过滤掉任何不需要的元数据,然后再传递到下一个 state。

I found one solution, add the outputPath :我找到了一个解决方案,添加outputPath

return new LambdaInvoke(this, 'lamba', {
      lambdaFunction: Function.fromFunctionArn(this, name, this.createLabmdaArn('applicationPdf')),
      outputPath: '$.Payload',
    });

This seems to work and might be THE solution.这似乎可行并且可能是解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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