javascript - AWS Lambda 持续时间与函数运行时间

标签 javascript node.js amazon-web-services lambda serverless-framework

我注意到我的 Nodejs Lambda 函数在 Cloud watch 日志中存在持续时间与函数运行时间问题。我正在使用无服务器插件来部署/编码我的功能。

这是我的 lambda 函数代码:

module.exports.handler = function (event, context, cb) {
    console.time("function_run_time");
    myFunction(function (callback) {
       console.timeEnd("function_run_time");
       return cb(null, callback)
    });
};

在云监视日志中,我收到以下内容

2016-05-25T00:18:58.881Z    45cd0785-ccce-11e6-818f-cb61404e173c    function_run_time: 477ms 
REPORT RequestId: 45cd0785-ccce-11e6-818f-cb61404e173c  Duration: 1866ms    Billed Duration: 1900 ms Memory Size: 1024 MB   Max Memory Used: 39 MB

我想知道为什么函数运行时间为 477 毫秒,但持续时间为 1866 毫秒。

我的代码中是否需要调用某些内容才能提前结束 Lamdba 函数?

谢谢

最佳答案

检查调用回调后是否有代码在运行 参见这里:aws lambda

By default, the callback will wait until the Node.js runtime event loop is empty before freezing the process and returning the results to the caller. You can set this property to false to request AWS Lambda to freeze the process soon after the callback is called

此外,如果您使用 older version您应该调用带有 Lambda 的 Node context.succeed();context.fail(error) 结束函数。

关于javascript - AWS Lambda 持续时间与函数运行时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37426088/

相关文章:

javascript - 如何防止 jQuery 日期选择器在初始页面加载时弹出,但仍滚动到日期选择器文本框

javascript - 值未更新

javascript - Uncaught ReferenceError : angular is not defined (Using testem)

amazon-web-services - 如何从 Cloud Formation 获取 Elastic Container Repository URI?

javascript - 可能/如何在鼠标焦点上调整 iframe 大小?

javascript - 鼠标悬停时水平展开导航栏

node.js - nodejs , socket.io 简单的代码内存泄漏

javascript - Node.JS 主体解析器问题

mysql - 如何在 Aurora 中启用 lambda_sync/lambda_async 函数

amazon-web-services - 如何使用 SFTP 中的 pem 文件将 EC2 实例与 VSCode Directy 连接