我试图从调用一个异步lambda表达式中的另一个lambda函数,而且我发现,如果调用函数退出太快,它没有得到执行.
换句话说,以下内容永远不会奏效.LambdaFunction2永远不会被调用.
function lambdaFunction1(event, context) {
callLambdaFunction2();
context.done(null);
}
Run Code Online (Sandbox Code Playgroud)
但是在LambdaFunction1退出之前添加一个小延迟确实可以工作到目前为止:
function lambdaFunction1(event, context) {
callLambdaFunction2();
setTimeout(
function() {
context.done(null);
}, 500
);
}
Run Code Online (Sandbox Code Playgroud)
我担心的是等待500ms是一个相当随意的幻数.有没有人遇到类似的问题,发现更有原则的修复?
callLambdaFunction2()可能在context.done(null)导致处理程序退出之前没有完成.
要解决这个问题,您需要调用它context.done作为回调.例如:
lambda.invoke({
FunctionName: "functionName",
InvocationType: 'Event',
Payload: JSON.stringify(event)
}, function(err, data) {
if (err) return context.done(err, null);
return context.done(null, data);
});
Run Code Online (Sandbox Code Playgroud)
如果这不是解决方案,您能说明您的实施方式callLambdaFunction2吗?
| 归档时间: |
|
| 查看次数: |
1002 次 |
| 最近记录: |