Trying to use aws-sdk from inside NodeJS AWS Lambda does timeout and not work, why?

2.4k Views Asked by At

I'm trying to use aws-sdk from NodeJS AWS Lambda where the Lambda is running inside a VPC on AWS. What I find is that when I make the AWS API call in my Lambda and then execute the Lambda it just times out with "Task timed out after 180.05 seconds", I have no result back from AWS API call.

Without the AWS API call then the Lambda works normally, of course without any AWS API result.

Why is this? Is it the case that aws-api is trying to call out to the internet and this VPC Lambda has no internet connection? What can I do to allow it to work?

1

There are 1 best solutions below

2
On

It seems like you lambda function is timeout after 180 sec's, so you should try to use maximum timeout limit of lambda function which is around 300 sec's previously but now it is around 15 minutes yes it's minutes not sec's. It's depend on your requirements what timeout limit you wanna use.

https://aws.amazon.com/about-aws/whats-new/2018/10/aws-lambda-supports-functions-that-can-run-up-to-15-minutes/

To configure the timeout limit in nodeJS you can try the following way:

// maxRetries: retry count / timeout: socket timeout / connectTimeout: new connection timeout

var AWS = require('aws-sdk');

AWS.config.update({

    maxRetries: 2,

    httpOptions: {

        timeout: 30000,

        connectTimeout: 5000

    }

});

For more information:

https://aws.amazon.com/premiumsupport/knowledge-center/lambda-function-retry-timeout-sdk/ https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Lambda.html