node.js - 如何停止AWS Lambda [Nodejs]

标签 node.js amazon-web-services aws-lambda

我在 AWS Lambda 中有一个函数使用运行时 Node.js 6.10 。 Lambda 可以正常运行我的代码,但即使代码已完成,仍会继续“执行”。我希望发生的是 Lambda 在代码完成时停止。我在下面列出了我的日志,看看是否有人可以看到问题所在。请注意我结束函数的回调返回 success

{ "errorMessage": "2017-12-07T17:50:55.618Z e4a5bb77-db76-11e7-b2e6-514284a81613 Task timed out after 120.09 seconds" }

START RequestId: e4a5bb77-db76-11e7-b2e6-514284a81613 Version: $LATEST 2017-12-07T17:48:55.527Z e4a5bb77-db76-11e7-b2e6-514284a81613 -L-llvVALjYpyUV0M6EG //gotten from code 2017-12-07T17:48:58.652Z e4a5bb77-db76-11e7-b2e6-514284a81613 http://www.loopnewsbarbados.com/content/bitcoin-worth-millions-stolen-days-us-exchange-opens-1 //gotten from code 2017-12-07T17:49:01.150Z e4a5bb77-db76-11e7-b2e6-514284a81613 crisis, //gotten from code 2017-12-07T17:49:01.232Z e4a5bb77-db76-11e7-b2e6-514284a81613 success //successful callback END RequestId: e4a5bb77-db76-11e7-b2e6-514284a81613 REPORT RequestId: e4a5bb77-db76-11e7-b2e6-514284a81613 Duration: 120093.31 ms Billed Duration: 120000 ms Memory Size: 128 MB Max Memory Used: 34 MB<br/> 2017-12-07T17:50:55.618Z e4a5bb77-db76-11e7-b2e6-514284a81613 Task timed out after 120.09 seconds

最佳答案

您需要在 context.succeed 或 context.fail 之后的函数中返回,以防止进一步执行。

如果您在处理程序中使用callback(null, result)/(err)而不是context.succeed()/fail(),则需要将callbackWaitsForEmptyEventLoop设置为false。

参见https://gist.github.com/hassy/eaea5a958067211f2fed02ead13c2678

关于node.js - 如何停止AWS Lambda [Nodejs],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47701173/

相关文章:

javascript - Grunt 多次连接 JS 文件

javascript - 检测客户端断开连接

ruby - Rspec - 如何 stub 第 3 方异常

java - 如何减少代码中的 Lambda 冷启动时间?

amazon-web-services - AWS Lambda函数的 promise 无法解析/返回-Nightmare JS

node.js - Nodejs ember-预编译抛出 TypeError

node.js - Nginx + Node JS + Express JS 产生 502 错误

javascript - 当调用源自浏览器 AWS SDK 时,AWS Lambda 设置响应 header

java - Hadoop 2.6.x 和 Amazon AWS SDK Library 冲突 http-core 冲突

python - AWS DynamoDB Python - boto3 Key() 方法无法识别(查询)