Checking a DB table before doing an insert using AWS Lambda
Your code is already pretty good by common standards, IMO.

If it is possible, you can try to adopt ES7's async/await. The code will become more linear, while still asynchronous.

Watch out for browser compatibility though.



export async function main(event) {

  const data = await dynamo
    .get({ TableName: 'client', Key: { id: event.name } })
    .promise();

  if (data.Item) {
    throw new Error(`Client name '${event.name}' is already in use.`);
  }

  const timestamp = new Date().getTime();

  return await dynamo
    .put({
      TableName: 'client',
      Item: {
        id: event.name,
        created: timestamp,
        updated: timestamp,
        deleted: null
      },
      ConditionExpression: 'attribute_not_exists(id)'
    })
    .promise();

}