我有一个Node.js 8.10 Lambda。它响应对我的API网关的POST请求。
我想:
我的代码是:
function handler(event, context, lambdaCallback) {
//210000 milliseconds is 3.5 minutes
let timeToWait = 210000;
//respond to the caller and continue to process the request
lambdaCallback(null, {"message": "process started"});
setTimeout(() => {
doSomethingUseful();
}, timeToWait);
}
在所有情况下,doSomethingUseful()在指定的超时后运行。
问题在于我没有得到回复。我认为API网关响应超时会导致响应 - 通常我得到:{ "message": "Endpoint request timed out" }
。
我认为API网关响应超时会导致响应,因为如果我将timeToWait减少到一个微不足道的值,我会得到预期的响应({"message": "process started"}
)。
关于如何在setTimeout结束前发送快速响应的任何想法?
答案 0 :(得分:2)
将AWS Step Functions与wait state
一起使用答案 1 :(得分:0)
AWS Step Function作为公认的答案是一个很好的选择(对于特定要求可能是最好的选择)。但是,我也想指出,您可以使用 SQS and delayed events which trigger a lambda function.
注意:对于那些希望获得OP所希望的3.5分钟以上时间的人,最长时间为15分钟。
对于Event
,您还可以对InvocationType
用asyncInvoke
进行an Invoke of another lambda function(异步调用)。这样可以在用户收到响应后再运行,但是显然第二lambda的操作必须完全隔离,因为我们无法从中返回响应。这对于OP来说绝对不是正确的解决方案,因为没有理由花费3.5分钟的lambda运行时间让它什么也不做,但是这种模式非常有帮助。
当我需要进行vpc内处理时,我使用<--here is the link-->
<a href="thenextpage.php?id=".$row['id'].""><comment</a>\
<--here i get back the variable-->
$idcomment = $_GET['id'];
<--here here is the sql query-->
$sql = "INSERT INTO commentaire (id, idUsers, textec, datec)
VALUES('$idcomment' '$iduser', '$commentaire', '$date')";
模式,我不希望用户在lambda上处理可怕的10s VPC冷启动时不使用它。请求的必要/连接部分。
注意:如果您使用以上两种方法之一,高度都建议您为lambda函数设置一个Dead Letter Queue,因为异步调用会多次重试执行当失败。
无论如何,不要贬低基于OP需求的最佳答案,但认为查看职位上发生的其他可能性还有其他帮助!