AWS Lambda - Timeout error with faunadb query

I just got started with AWS Lambda and have a simple lambda function:

const handler: ValidatedEventAPIGatewayProxyEvent = async (event) => {
// FaunaDB driver
var auth = new faunadb.Client({
secret: process.env.FAUNA_AUTH_SECRET,
})

  // FaunaDB query
  var result = await auth.query(
    q.Add(50, 50)
  )

  console.log('Result:', result)

  return {
    statusCode: 200,
    body: JSON.stringify(result),
  }
}

The problem I have is that whenever I execute a faunadb query my lambda function times out. The function does print the correct result to the console but is not able to return the result somehow. It doesn’t seem like a faunadb problem, but the weird thing about this is that when I access another api with axios for example, it works perfectly. The lambda function has a timeout of 10s and I am using the serverless framework with nodejs and typescript as well as the template provided here: Template.

Does anyone have an idea what the issue might be?

Found the issue. Within the handler I set the context.callbackWaitsForEmptyEventLoop = false. Alternatively when using middy you can use this middleware

2 Likes