amazon-web-services - 有什么方法可以在代码级别捕获AWS lambda超时错误?

标签 amazon-web-services aws-lambda

有什么办法可以在代码级捕获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/

相关文章:

javascript - SAM 本地启动 API CORS 问题

c# - Elasticsearch:WAITING长时间运行的请求完成

amazon-web-services - ALB 未正确传播响应 header

aws-lambda - 以编程方式将暂停或长时间延迟引入 Alexa 技能捕获输入

amazon-web-services - AWS 无法验证提供的访问凭证。仅在特定区域验证失败

使用 lambda 在 AWS 上部署 Visual Studio 中的 Python 项目?

amazon-web-services - 具有多个标签的 DynamoDB 查询

python - Lambda 错误 : no module found. Cryptography.hamtaz.bindings._constant_time

amazon-web-services - AWS Lambda 负载

node.js - 无法访问 Lambda 函数中的环境变量