Unable to return mysql query results

I am working off a netlify demo project repo I added a new lambda function mytest.js. In mytest I am connecting to a mysql db and trying to return the results of the query.

const mysql = require('mysql')
const pool = mysql.createPool({ ... })

exports.handler = (event, context, callback) => {

  context.callbackWaitsForEmptyEventLoop = false

  try {
    pool.getConnection(function(err, connection) {
      connection.query('SELECT * FROM mytable order by DatePublished desc', function(error, results, fields) {
        connection.release()
        
          if (error) {
            console.log('calling callback with error')
            callback(error);
          }
          else {
            console.log(`calling callback with results`)
            console.log(results);
            callback(null, {
              statusCode: 200,
              body: results
            })
          }             
      })
    })
  } 
  catch (e) {
      console.log('errored in try catch')
      console.log(e)
  } 
}

When I deploy this and hit the url, I can see the query is successful (in the logs) but returning the data always results in a 502.

I tried the same thing in postman and got nothing back in the body.

When I set body: 'test string' it will return “test string” correctly so I am really confused as to why the results will be available when they are logged but not in the callback.

results in the log is an array of 208 pretty simple objects with about 7 properties each all of which are small data like ints and url strings

Any help with this would be appreciated.

I also posted this on stack overflow and thankfully someone suggested a very simple answer.

I needed to stringify my results in the body property of the response

callback(null, {
          statusCode: 200,
          headers: {
            'Access-Control-Allow-Origin': '*',
            'Content-Type': 'application/json'
          },
          body: JSON.stringify(results)
        })

thanks a ton for sharing your solutiom @Ju66ernaut!