getglad
getglad

Reputation: 2563

lambda.invoke call through Node AWS SDK is timing out at 5 minutes while Lambda is completing under 4 minutes

I have a Lambda function that is set to timeout at 5 minutes, and occasionally when I invoke the function using the node SDK, I am getting a timeout error after 5 minutes.

However, when I have checked the CloudWatch logs after getting the client-side error, and am seeing the function successfully complete after ~3:30 minutes of execution time.

I have also noticed that the client side will log the timeout 2 minutes before the CloudWatch logs read that the function completed (ie, client side error timestamps at 4:08 and the CloudWatch successful end timestamps at 4:10), but I am assuming that is a lag between log writes, not run time. Thought I would mention it just in case that is something worth thinking more about.

From what I can tell, when the function runs under two minutes, it is consistently getting a positive response.

Code looks like this:

let aws_config = new AWS.Config({
    region: 'us-east-1',
    credentials: credentials,
    httpOptions: { 
        proxy: process.env.HTTP_PROXY,
        timeout: 300000
    }
})

var lambda = new AWS.Lambda(aws_config);

lambda.invoke(params, (err, data: Result) => {
  ...
}

Error looks like this:

{ TimeoutError: Connection timed out after 300000ms
at ClientRequest.<anonymous> (.../node_modules/aws-sdk/lib/http/node.js:83:34)
at Object.onceWrapper (events.js:273:13)
at ClientRequest.emit (events.js:182:13)
at ClientRequest.EventEmitter.emit (domain.js:442:20)
at Socket.emitRequestTimeout (_http_client.js:661:40)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at Socket.EventEmitter.emit (domain.js:442:20)
at Socket._onTimeout (net.js:449:8)
at ontimeout (timers.js:425:11)
message: 'Connection timed out after 300000ms',
  code: 'TimeoutError',
  time: 2018-10-05T20:08:35.719Z,
  region: 'us-east-1',
  hostname: 'lambda.us-east-1.amazonaws.com',
  retryable: true } 'TimeoutError: Connection timed out after 300000ms\n    at ClientRequest.<anonymous> (.../node_modules/aws-sdk/lib/http/node.js:83:34)\n    at Object.onceWrapper (events.js:273:13)\n    at ClientRequest.emit (events.js:182:13)\n    at ClientRequest.EventEmitter.emit (domain.js:442:20)\n    at Socket.emitRequestTimeout (_http_client.js:661:40)\n    at Object.onceWrapper (events.js:273:13)\n    at Socket.emit (events.js:182:13)\n    at Socket.EventEmitter.emit (domain.js:442:20)\n    at Socket._onTimeout (net.js:449:8)\n    at ontimeout (timers.js:425:11)'

Upvotes: 2

Views: 1768

Answers (1)

Marc
Marc

Reputation: 174

Have you looked into

context.callbackWaitsForEmptyEventLoop = false;

Here'e a related SO posting: Why does AWS Lambda function always time out?

Upvotes: 1

Related Questions