<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def task(*args, **kwargs):
 """Async task decorator so that running Args: func (function):
 the function to be wrapped Further requirements: func must be an independent top-level function. i.e. not a class method or an anonymous function service (str):
 either 'lambda' or 'sns' remote_aws_lambda_function_name (str):
 the name of a remote lambda function to call with this task remote_aws_region (str):
 the name of a remote region to make lambda/sns calls against Returns: A replacement function that dispatches func() to run asynchronously through the service in question """


    func = None
    if len(args) == 1 and callable(args[0]):
        func = args[0]

    if not kwargs:  # Default Values
        service = 'lambda'
        lambda_function_name_arg = None
        aws_region_arg = None

    else:  # Arguments were passed
        service = kwargs.get('service', 'lambda')
        lambda_function_name_arg = kwargs.get('remote_aws_lambda_function_name')
        aws_region_arg = kwargs.get('remote_aws_region')

    capture_response = kwargs.get('capture_response', False)

    def func_wrapper(func):

        task_path = get_func_task_path(func)

        @wraps(func)
        def _run_async(*args, **kwargs):
            """
            This is the wrapping async function that replaces the function
            that is decorated with @task.
            Args:
                These are just passed through to @task's func

            Assuming a valid service is passed to task() and it is run
            inside a Lambda process (i.e. AWS_LAMBDA_FUNCTION_NAME exists),
            it dispatches the function to be run through the service variable.
            Otherwise, it runs the task synchronously.

            Returns:
                In async mode, the object returned includes state of the dispatch.
                For instance

                When outside of Lambda, the func passed to @task is run and we
                return the actual value.
            """
            lambda_function_name = lambda_function_name_arg or os.environ.get('AWS_LAMBDA_FUNCTION_NAME')
            aws_region = aws_region_arg or os.environ.get('AWS_REGION')

            if (service in ASYNC_CLASSES) and (lambda_function_name):
                send_result = ASYNC_CLASSES[service](lambda_function_name=lambda_function_name,
                                                     aws_region=aws_region,
                                                     capture_response=capture_response).send(task_path, args, kwargs)
                return send_result
            else:
                return func(*args, **kwargs)

        update_wrapper(_run_async, func)

        _run_async.service = service
        _run_async.sync = func

        return _run_async

    return func_wrapper(func) if func else func_wrapper