text: const DocumentClient = require('aws-sdk/clients/dynamodb').DocumentClient
  const dynamodb = new DocumentClient()
  const failureLambda = require('failure-lambda')
  
  const tableName = process.env.restaurants_table
  
  module.exports.handler = failureLambda(async (event, context) => {
    const req = JSON.parse(event.body)
    const theme = req.theme
    const restaurants = await findRestaurantsByTheme(theme, 8)
    return {
      statusCode: 200,
      body: JSON.stringify(restaurants)
    }
  })
  
  async function findRestaurantsByTheme(theme, count) {
    console.log(`finding (up to ${count}) restaurants with the theme ${theme}...`)
    const req = {
      TableName: tableName,
      Limit: count,
      FilterExpression: "contains(themes, :theme)",
      ExpressionAttributeValues: { ":theme": theme }
    }
  
    const resp = await dynamodb.scan(req).promise()
    console.log(`found ${resp.Items.length} restaurants`)
    return resp.Items
  }