Serverless: Replying timeout after 30000ms with using AWS EC2 and node.js

Viewed 15

first of all thanks a lot for reading my question.

I am facing a serverless timeout question while debugging...

Everything went successfully in handler and return to process.response.success() function. But as you can see in the terminal, after console log the response, nothing return and then shows the error message which is Serverless: Replying timeout after 30000ms.

We use MySQLWorkBench for DB, and serverless offline to deploy on AWS EC2. node version is 12.

Appreciate a lot if anyone knows how to debug what the lambda doesn't work on return anything which caused the timeout error.

enter image description here

handler function

export async function handler(event, context, callback) {
  let processor = new BoxCountProcessor(event, callback, Request)
  try {
    await processor.init(true)
    const tokenData = await processor.verifyToken()
    const count = await processor.getBoxCount(tokenData.email)
    const responseData = { statusCode: 200, data: count }
    await processor.close()
    return processor.response.success(responseData)
  } catch (err) {
    console.log(err)
    await processor.close()
    return processor.response.failure(err)
  }
}

response function

class Response {

  constructor(callback) {
    this.callback = callback
  }

  success = ({ statusCode, data }) => {
    console.log('>> response success ...')
    statusCode = statusCode || DEFAULT_RESPONSE.SUCCESS.statusCode
    const body = data || { result: DEFAULT_RESPONSE.SUCCESS.message }
    const response = { statusCode: statusCode, body: JSON.stringify(body) }
    console.log('response', response)
    return response
  }

  failure = ({ statusCode, message }) => {
    statusCode = statusCode || DEFAULT_RESPONSE.SERVER_BUSY.statusCode
    message = message ? { errorMessage: message } : { errorMessage: DEFAULT_RESPONSE.SERVER_BUSY.message }
    return { statusCode: statusCode, body: JSON.stringify(message) }
  }

}

export default Response

project dependencies

"dependencies": {
    "aws-sdk": "2.224.1",
    "bcryptjs": "2.4.3",
    "hasha": "3.0.0",
    "is-absolute-url": "2.1.0",
    "joi": "13.1.2",
    "jwk-to-pem": "2.0.0",
    "moment": "2.22.2",
    "mysql2": "1.5.3",
    "randomatic": "3.1.1",
    "request": "2.87.0",
    "sequelize": "4.37.6",
    "source-map-support": "0.5.4"
  }
0 Answers
Related