def _run_function_as_task(all_functions_list, function_name, kwargs=None):
  """Runs a specific function and its kwargs as an AppEngine task.

  Args:
    all_functions_list: string list, A list with all function names that are
        registered as bootstrap functions on the Loaner app.
    function_name: string, A specific function that should be ran as a task.
    kwargs: dict, Optional kwargs to be passed to the function that will run.

  Returns:
    The deferred task from AppEngine taskqueue.

  Raises:
    Error: if requested bootstrap method is not allowed or does not exist.
  """
  logging.debug('Running %s as a task.', function_name)
  function = all_functions_list.get(function_name)
  if function is None:
    raise Error(
        'Requested bootstrap method {} does not exist.'.format(function_name))
  if not kwargs:
    kwargs = {}
  kwargs['user_email'] = user.get_user_email()
  return deferred.defer(function, **kwargs)