Last active
September 19, 2022 17:20
-
-
Save hassy/eaea5a958067211f2fed02ead13c2678 to your computer and use it in GitHub Desktop.
Different behavior of context.succeed() vs callback() in AWS Lambda
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Lambda's timeout needs to be >5 seconds, 10 should do | |
// | |
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); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@DaVincii is right, I can use
callback()
and it completes the request as long as there's no other connection/process hanging, in my case the connection to the db was still open so my lambda would timeout and never complete the request, after closing the client connection it resolved as expected.