AWS Step Functions中的直通输入到输出

mat*_*sev 6 amazon-web-services aws-step-functions

如何Task将AWS Step Functions中的状态输入传递给输出?

阅读AWS文档中的输入和输出处理页面后,我使用了各种组合InputPath,ResultPathOutputPath.

州定义:

"First State": {
    "Type": "Task",
    "Resource": "[My Lambda ARN]",
    "Next": "Second State",
    "InputPath": "$.someKey",
    "OutputPath": "$"
}
Run Code Online (Sandbox Code Playgroud)

输入:

{
    "someKey": "someValue"
}
Run Code Online (Sandbox Code Playgroud)

预期结果

我希望输出First State(以及输入Second State)

{
    "someKey": "someValue"
}
Run Code Online (Sandbox Code Playgroud)

实际结果

[empty]
Run Code Online (Sandbox Code Playgroud)

如果输入更复杂,例如

{
    "firstKey": "firstValue",
    "secondKey": "secondValue"
}
Run Code Online (Sandbox Code Playgroud)

我想转发所有这些而不用担心(子)路径.

mat*_*sev 14

亚马逊国家语言中,声明:

如果ResultPath的值为null,则意味着将丢弃状态自身的原始输出,并且其原始输入将成为其结果.

因此,我将我的州定义更新为

"First State": {
    "Type": "Task",
    "Resource": "[My Lambda ARN]",
    "Next": "Second State",
    "ResultPath": null
}
Run Code Online (Sandbox Code Playgroud)

因此,当传递输入示例时,Task输入有效负载将被复制到输出,即使对于富对象,例如:

{
    "firstKey": "firstValue",
    "secondKey": "secondValue"
}
Run Code Online (Sandbox Code Playgroud)


小智 13

对于那些使用 CDK 的人来说,解决方案是使用显式aws_stepfunctions.JsonPath.DISCARD枚举而不是 None/null。

from aws_cdk import (
    aws_stepfunctions,
    aws_stepfunctions_tasks,
)

aws_stepfunctions_tasks.LambdaInvoke(
    self,
    "my_function",
    lambda_function=lambda_function,
    result_path=aws_stepfunctions.JsonPath.DISCARD,
)
Run Code Online (Sandbox Code Playgroud)

https://docs.aws.amazon.com/cdk/api/latest/docs/@aws-cdk_aws-stepfunctions.JsonPath.html#static-discard