AWS Lambda中的上下文与回调 [英] Context vs Callback in AWS Lambda
问题描述
我喜欢在AWS中使用lambda函数。它理想地减少了我维护服务器的时间。我的问题是当使用lambda时,有上下文对象和回调函数来终止函数。是否有任何使用回调超过上下文的用例。
I am loving using lambda functions in AWS. It ideally reduced my time in maintaining the servers anymore. My question is when using lambda there is context object and the callback function to terminate the function. Is there any use case of using callback over context.
有没有人能告诉我context.succeed()回调的行为(错误,消息)
Could anyone tell me the behavior of context.succeed() to callback(error,message)
var startedAt = new Date();
var interval = setInterval(function () {
console.log(startedAt, new Date());
}, 1000);
exports.handler = function (event, context, callback) {
setTimeout(function () {
console.log('returning');
// v1:
return callback(null);
// v2:
// return context.succeed();
}, 5000);
};
推荐答案
context.succeed
是较旧的处理方式,在0.10.42运行时支持(其中 callback
参数具体不支持)。如果你在较新的运行时(4.3和6.10)上运行,它是为了向后兼容而包含的,但现在正确的方式是使用回调
功能。
context.succeed
is the older way of doing things, and is supported under the 0.10.42 runtime (where the callback
parameter specifically isn't). If you're running on the newer runtimes (4.3 and 6.10), it's included for backwards compatibility, but the "proper" way is now to use the callback
functionality.
这篇关于AWS Lambda中的上下文与回调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!