1

I have an AWS Lambda function that connects to SQL DB and the timeout for lambda has been set to 120 seconds. But when there is some issue with the DB connection or query execution, lambda is getting timed out after 60 seconds. Below is my DB config. I used node-mssql module.

const DBConfig = {
    user: Config.DBUser,
    password: pswd,
    server: Config.DBHost,
    port: Config.DBPort,
    database: Config.DBName,
    connectionTimeout: 60000,
    requestTimeout: 60000,
    options: {
        encrypt: false
    }
}
John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
Abirami
  • 223
  • 6
  • 21

3 Answers3

0

This is because your connection is timing out when trying to connect to the database and you're not handling the timeout correctly inside the lambda function and there for your lambda will timeout.

Chad Elias
  • 637
  • 6
  • 7
0

Lambda can not get timed out before its duration exceeds the configured timeout value. Other options for the execution termination are: - The handler function has finished. - An unhandled exception was raised. In NodeJS specifically, the error message in the Lambda logs will be: ‘process exited before completing request’ (though it doesn’t mean that there was a timeout). - There is an out of memory problem, but this doesn’t seem like your problem.

Ronyis
  • 1,803
  • 16
  • 17
0

Have you tried to increase the memory of your lambda function? In the past, when I bumped up the memory to 1GB+ this seems to have solved a number of connection problems for me.

J00N
  • 871
  • 5
  • 4