我喜欢在 AWS 中使用 lambda 函数。它理想地减少了我维护服务器的时间。我的问题是使用 lambda 时有上下文对象和回调函数来终止函数。有没有在上下文中使用回调的用例。
谁能告诉我 context.succeed() 到 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)上运行,则包含它是为了向后兼容,但现在“正确”的方法是使用 callback
功能。
关于javascript - AWS Lambda 中的上下文与回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47906116/