简体   繁体   English

在59.05秒后让Task超时aws lambda nodejs

[英]getting Task timed out after 59.05 seconds aws lambda nodejs

I am trying to write a lambda function in node 8.10 supported by aws lambda this is with reference to my previous question 我正在尝试在AWS Lambda支持的节点8.10中编写Lambda函数,这是参考我之前的问题

I am trying node async/await , same code work when I run it in my local(and is not even taking a second to get the response back) but when I am trying it in lambda getting time out error, here the code control is getting inside promise and printing url urltohit with the correct url but after it is getting stuck, have tried different thing like increasing the time in lambda config and even tried node request instead of http but still getting the same error. 我正在尝试节点异步/等待,当我在本地运行它时同样的代码工作(甚至没有花一秒钟来获得响应),但是当我在lambda中尝试它得到超时错误时,这里的代码控制是进入promise并使用正确的URL打印URL urltohit ,但是在卡住之后,尝试了其他方法,例如增加lambda config中的时间,甚至尝试了节点请求而不是http,但仍然遇到相同的错误。

'use strict'; “严格使用”;

var http = require('http');
var request = require('request');

exports.handler = async (event) => {
  const response = await getRequest(urltohit);
  console.log(response);

}
 const getRequest = async (url) => {
  console.log("Test log");
  return new Promise((resolve, reject) => {
    console.log(`url ${url}`);
      http.get(url, function(res) {
          console.log("Got response: " + res.statusCode);
          resolve(res.statusCode);
      }).on('error', function(e) {
          console.log("Got error: " + e.message);
          reject(e.message);
      });
  });
}

You need to call callback after function execution. 您需要在函数执行后调用callback

exports.handler = async (event, context, callback) => {
  const response = await getRequest(urltohit);
  console.log(response);
  callback(null);
}

It's lambda behaviour to keep function running until callback called. 保持函数运行直到调用回调是lambda行为。
More could be found in official documentation 可以在官方文档中找到更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM