有什么办法可以在代码级捕获AWS lambda timed out
错误,以便我有机会在退出lambda
函数之前处理该错误?
最佳答案
尽管lambda环境不会触发“定时退出”事件,但您可以自己进行一些琐碎的操作。
每种语言都有context
对象公开的功能
到get the remaining time in milliseconds。
您可以将其与所用任何语言的计时器功能配合使用,以确保在超时之前得到通知。
例如(节点):
function handler(event, context, callback) {
const timer = setTimeout(() => {
console.log("oh no i'm going to timeout in 3 seconds!");
// &c.
}, context.getRemainingTimeInMillis() - 3 * 1000);
// rest of code...
clearTimeout(timer);
callback(null, result);
}
关于amazon-web-services - 有什么方法可以在代码级别捕获AWS lambda超时错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53478200/