Consider this example from docs for Amazon DynamoDB, here we have:
dynamoDb.scan(params, onScan);
function onScan(err, data) {
      if (err) {
          return;
      } else {
        collectedItems.push(data.Items);
        const response = {
          statusCode: 200,
          headers: {
            'Access-Control-Allow-Origin': '*',
          },
          body: JSON.stringify(collectedItems),
        };
        callback(null, response);
        // continue scanning if we have more movies, because
        // scan can retrieve a maximum of 1MB of data
        if (typeof data.LastEvaluatedKey != "undefined") {
            console.log("Scanning for more...");
            params.ExclusiveStartKey = data.LastEvaluatedKey;
            dynamoDb.scan(params, onScan);
        }
      }
  }
that should show me  collectedItems  as json response for API Gateway. But it returns
{
 message: "Internal server error"
}