@Override
  public void createTable(
      String tableName, KeySchema ks, ProvisionedThroughput provisionedThroughput)
      throws DataAccessException {
    CreateTableRequest request =
        new CreateTableRequest()
            .withTableName(tableName)
            .withKeySchema(ks)
            .withProvisionedThroughput(provisionedThroughput);

    try {
      CreateTableResult result = ddb.createTable(request);
      // now we must wait until table is ACTIVE
      TableDescription tableDescription = waitTillTableState(tableName, "ACTIVE");
      if (!"ACTIVE".equals(tableDescription.getTableStatus())) {
        throw new DataStoreOperationException(
            "could not create table "
                + tableName
                + ", current table description: "
                + tableDescription);
      }
    } catch (AmazonClientException e) {
      throw new DataStoreOperationException(
          "problem with table: "
              + tableName
              + ", key schema: "
              + ks
              + ", provisioned throughput: "
              + provisionedThroughput,
          e);
    }
  }
 private TableDescription waitTillTableState(String tableName, String desiredState) {
   int attempt = 0;
   TableDescription tableDescription = null;
   do {
     tableDescription =
         ddb.describeTable(new DescribeTableRequest().withTableName(tableName)).getTable();
     attempt++;
     try {
       Thread.sleep(200);
     } catch (InterruptedException e) {
     }
   } while (attempt < 1000 && !desiredState.equals(tableDescription.getTableStatus()));
   return tableDescription;
 }