AWS Step Functions:将任务输入与* partial *任务输出结合 [英] AWS Step Functions: Combine task input with *partial* task output

查看:107
本文介绍了AWS Step Functions:将任务输入与* partial *任务输出结合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AWS Step函数.我已经阅读了 InputPath上的文档,OutputPath和ResultPath .我的问题是我想将 input 到Lambda Task的值与任务的 partial output 组合起来.

I'm working on AWS Step functions. I've read the documentation on InputPath, OutputPath, and ResultPath. My problem is that I want to combine values from the input to a Lambda Task with a partial output from the task.

任务的输入类似于以下内容.我想继续将这些值传递给后续任务.

The input to the task is similar to below. I want to continue passing these values on to subsequent tasks.

{
    "previous_task_result": 100,
    "next_task_input": "asdf"
}

我想要的是让Lambda Task的输出看起来像这样:

What I would like, is to have the output of my Lambda Task look like this:

{
    "previous_task_result": 100,
    "next_task_input": "asdf",
    "current_task_result": {
        "val1": "ghjk",
        "val2": [0,2,13,100]
    }
}

特定的问题是Lambda任务的原始输出看起来像这样.我只关心Payload节点.其余的输出是样板,我不想通过步进功能"传递.

The specific problem is that the raw output of the Lambda Task looks like this. I only care about the Payload node. The rest of the output is boilerplate I would rather not pass through the Step Function.

{
  "resourceType": "lambda",
  "resource": "invoke",
  "output": {
    "ExecutedVersion": "$LATEST",
    "Payload": {
        "val1": "ghjk",
        "val2": [0,2,13,100]
    },
    "SdkHttpMetadata": {
      "HttpHeaders": {
        "Connection": "keep-alive",
        "Content-Length": "42",
        "Content-Type": "application/json",
        "Date": "Tue, 25 Feb 2020 14:36:29 GMT",
        "X-Amz-Executed-Version": "$LATEST",
        "x-amzn-Remapped-Content-Length": "0"
      },
      "HttpStatusCode": 200
    },
    "SdkResponseMetadata": {
      "RequestId": "redacted"
    },
    "StatusCode": 200
  }
}

我了解如何使用ResultPathOutputPath将输入与输出组合,或将输出分配给特定节点,但是我找不到的是仅合并Payload节点的方法从具有现有输入的结果中得出.

I understand how to use ResultPath and OutputPath to combine the input with the output, or assign the output to a specific node, but what I can't find is a way to merge just the Payload node from the result with the existing input.

推荐答案

使用Lambda任务状态时,可以通过3种方法来构造任务状态:

When working with Lambda Task States there's 3 ways in which you can structure the your task state:

1.请求响应:

此方法返回完整的API响应,包括SdkHttpMetadata字段.我怀疑返回完整HTTP响应的原因是因为这是您可以从Step Function异步调用Lambda函数的唯一方法(异步Lambda调用仅返回状态码).示例:

This method returns the full API response including the SdkHttpMetadata field. I suspect the reason for returning the full HTTP response is because this is the only way in which you can invoke a Lambda function asynchronously from Step Function (Asynchronous Lambda invocations only return a status code). Example:

"CallLambda": {
    "Type": "Task",
    "Resource": "arn:aws:states:::lambda:invoke",
    "Parameters": {
        "FunctionName": "MyFunction",
        "InvocationType": "Event|RequestResponse|DryRun",
        "Payload.$": "$"
    },
    "End": true
}

2. Lambda ARN作为资源:

我相信这就是您要寻找的.当将Lambda函数的ARN指定为资源时,Step Functions将同步调用Lambda函数,并且仅返回Lambda函数的结果,而不返回API响应元数据.在这种情况下,您的状态输入将作为有效负载传递到Lambda函数,或者您可以使用InputPath/Parameters过滤/修改作为有效负载发送的数据.

I believe this is what you are looking for. When specifying the ARN of the Lambda function as the Resource, Step Functions will invoke your Lambda function synchronously and return only the result from your Lambda function without the API response metadata. In this case your State Input will be passed as the payload to your Lambda function or you can use InputPath/Parameters to filter/modify the data sent as the Payload.

"CallLambda": {
    "Type": "Task",
    "Resource": "arn:aws:lambda:us-west-2:123456789012:function:my-function",
    "ResultPath": "$.current_task_result",
    "End": true
}

使用示例中的输入,上述任务将为您提供如下输出:

Using the input as in your example the above Task will give you the output as follows:

{
    "previous_task_result": 100,
    "next_task_input": "asdf",
    "current_task_result": {
        <Your Lambda Functions Result>
    }
}

3. .WaitForTaskToken:

将令牌传递给您的函数,暂停执行,直到收到对SendTaskSuccess或SendTaskFailed的调用(此方法将仅从SendTaskSuccess或SendTaskFailed返回结果/错误,而没有其他HTTP元数据).

Passes a token to your function, pauses the execution untill either a call to SendTaskSuccess or SendTaskFailed has been received (this method will only return the Result/Error from SendTaskSuccess or SendTaskFailed with no additional HTTP metadata).

"CallLambda": {
    "Type": "Task",
    "Resource":"arn:aws:states:::lambda:invoke.waitForTaskToken",
    "Parameters": {
        "FunctionName": "MyFunction",
        "Payload":{  
           "token.$":"$$.Task.Token"
        }
    },
    "End": true
}

这篇关于AWS Step Functions:将任务输入与* partial *任务输出结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆