[英]How do I use Heartbeat with a Callback Return Step Function in my Lambda Function?
My Lambda function is required to send a token back to the step function for it to continue, as it is a task within the state machine.我的 Lambda function 需要将令牌发送回步骤 function 才能继续,因为这是 state 机器中的一项任务。
Looking at my try/catch
block of the lambda function, I am contemplating:看着我的 lambda function 的
try/catch
块,我正在考虑:
SendTaskHeartbeatCommand
and SendTaskSuccessCommand
SendTaskHeartbeatCommand
和SendTaskSuccessCommand
的顺序SendTaskHeartbeatCommand
SendTaskHeartbeatCommand
所需参数SendTaskHeartbeatCommand
to the catch
block, and then if yes, which order they should go in.SendTaskHeartbeatCommand
添加到catch
块,然后如果是,它们应该按哪个顺序添加 go。 Current code:当前代码:
try {
const magentoCallResponse = await axios(requestObject);
await stepFunctionClient.send(new SendTaskHeartbeatCommand(taskToken));
await stepFunctionClient.send(new SendTaskSuccessCommand({output: JSON.stringify(magentoCallResponse.data), taskToken}));
return magentoCallResponse.data;
} catch (err: any) {
console.log("ERROR", err);
await stepFunctionClient.send(new SendTaskFailureCommand({error: JSON.stringify("Error Sending Data into Magento"), taskToken}));
return false;
}
I have read the documentation for AWS SDK V3 for SendTaskHeartbeatCommand
and am confused with the required input
.我已阅读 SendTaskHeartbeatCommand 的 AWS
SendTaskHeartbeatCommand
V3 文档,但对所需的input
感到困惑。
The SendTaskHeartbeat and SendTaskSuccess API actions serve different purposes. SendTaskHeartbeat 和 SendTaskSuccess API 操作有不同的用途。
When your task completes, you call SendTaskSucces to report this back to Step Functions and to provide the results from the Task that your workflow can then process.当您的任务完成时,您调用 SendTaskSucces 以将此报告回 Step Functions 并提供您的工作流随后可以处理的任务结果。 You do not need to call SendTaskHeartbeat before SendTaskSuccess and the usage you have in the code above seems unnecessary.
您不需要在 SendTaskSuccess 之前调用 SendTaskHeartbeat 并且上面代码中的用法似乎没有必要。
SendTaskHeartbeat is optional and you use it when you've set "HeartbeatSeconds" on your Task. SendTaskHeartbeat 是可选的,当您在任务上设置“HeartbeatSeconds”时可以使用它。 When you do this, you then need your worker (ie the Lambda function in this case) to send back regular heartbeats while it is processing work.
当您这样做时,您需要您的工作人员(即本例中的 Lambda function)在处理工作时发回定期心跳。 I'd expect that to be running asynchronously while your code above was running the first line in the try block.
我希望在上面的代码运行 try 块中的第一行时异步运行。 The reason for having heartbeats is that you can set a longer TimeoutSeconds (or dynamically using TimeoutSecondsPath) than HeartbeatSeconds, therefore failing / retrying fast when the worker dies (Heartbeat timeout) while you still allow your tasks to take longer to complete.
有心跳的原因是您可以设置比 HeartbeatSeconds 更长的 TimeoutSeconds(或动态使用 TimeoutSecondsPath),因此当工作人员死亡(心跳超时)时快速失败/重试,同时您仍然允许您的任务花费更长的时间来完成。
That said, it's not clear why you are using.waitForTaskToken with Lambda. Usually, you can just use the default Request Response integration pattern with Lambda. This uses the synchronous invoke mode for Lambda and will return the response back to you without you needing to integrate back with Step Functions in your Lambda code.也就是说,不清楚为什么要使用 Lambda 的 .waitForTaskToken。通常,您可以只使用默认的请求响应集成模式和 Lambda。这使用 Lambda 的同步调用模式,并且无需您即可将响应返回给您在您的 Lambda 代码中与 Step Functions 集成。 Possibly you are reading these off of an SQS queue for concurrency control or something.
可能您正在从 SQS 队列中读取这些内容以进行并发控制或其他操作。 But if not, just use Request Response.
但如果没有,只需使用 Request Response。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.