parameters: (event, context)
return_statement: return result
docstring: Main entry point for the service AWS Lambda Function. It dispatches requests
      to the correct code for processing.
  
      :param event: An object containing the request data as constructed by the service's
      AWS API Gateway. This object is expected to include the following properties:
  
              * module - the name of the module that implements the handler function.
                This name is prefixed with "api." so that only modules defined in the
                api directory will be loaded.
  
              * function - the name of the handler function. The function must be
                decorated using @dispatch.handler or the dispatcher will not execute it.
                The function will be passed a dispatch. Request object followed by the
                value of the parameters dict passed as **kwargs.
  
              * parameters - an dict containing parameter values.
      :param context: The AWS Lambda defined context object for the request.
      See https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html.
  
      :return: The result including request id from calling to Service AWS function
docstring_summary: Main entry point for the service AWS Lambda Function. It dispatches requests
      to the correct code for processing.
docstring_tokens: Main entry point for the service AWS Lambda Function . It dispatches requests to the correct code for processing .
function: def dispatch(event, context):
      """
      Main entry point for the service AWS Lambda Function. It dispatches requests
      to the correct code for processing.
  
      :param event: An object containing the request data as constructed by the service's
      AWS API Gateway. This object is expected to include the following properties:
  
              * module - the name of the module that implements the handler function.
                This name is prefixed with "api." so that only modules defined in the
                api directory will be loaded.
  
              * function - the name of the handler function. The function must be
                decorated using @dispatch.handler or the dispatcher will not execute it.
                The function will be passed a dispatch. Request object followed by the
                value of the parameters dict passed as **kwargs.
  
              * parameters - an dict containing parameter values.
      :param context: The AWS Lambda defined context object for the request.
      See https://docs.aws.amazon.com/lambda/latest/dg/python-context-object.html.
  
      :return: The result including request id from calling to Service AWS function
      """
      aws_request_id = context.aws_request_id
      if isinstance(sys.stdout, logging.CloudCanvasLogger):
          logging.CloudCanvasLogger.override_id(aws_request_id=aws_request_id)
      else:
          logging.CloudCanvasLogger.init_instance(
              aws_request_id=aws_request_id, output=sys.stdout)
  
      module_name = event.get('module', None)
      if not module_name:
          raise ValueError('No "module" property was provided n the event object.')
          
      function_name = event.get('function', None)
      if not function_name:
          raise ValueError('No "function" property was provided in the event object.')
  
      print('request id {} has module {} and function {}'.format(
          aws_request_id, module_name, function_name))
  
      module = importlib.import_module('api.' + module_name)
  
      function = getattr(module, function_name, None)
  
      if not function:
          raise ValueError('The module "{}" does not have an "{}" attribute.'.format(module_name, function_name))
  
      if not callable(function):
          raise ValueError('The module "{}" attribute "{}" is not a function.'.format(module_name, function_name))
  
      if not hasattr(function, 'is_dispatch_handler'):
          raise ValueError('The module "{}" function "{}" is not a service dispatch handler.'.format(module_name, function_name))
  
      parameters = event.get('parameters', {})
  
      __check_function_parameters(function, parameters)
  
      # The request parameters are logged after finding the handler function since that's where the logging filters are defined.
      # Request logging is also after the request validation so that the logging filters don't have to know how to filter unexpected data.
      filtered_parameters = __apply_logging_filter(function, parameters)
      print('dispatching function {} with parameters {}'.format('api.{}.{}'.format(module_name, function_name), filtered_parameters))
  
      request = Request(event, context)
      result = {}
  
      try:
          result = function(request, **parameters)
      except Exception as e:
          error_message = 'CloudCanvas_request_id : {} failed with {}'.format(aws_request_id, message(e))
          raise ClientError(error_message) from e
  
      try:
          result["CloudCanvas_request_id"] = aws_request_id
      except Exception as e:
          print('Failed to add request id to request result {}'.format(message(e)))
  
      filtered_result = __apply_logging_filter(function, result)
      print('returning result {}'.format(filtered_result))
  
      return result
function_tokens: def dispatch ( event , context ) : aws_request_id = context . aws_request_id if isinstance ( sys . stdout , logging . CloudCanvasLogger ) : logging . CloudCanvasLogger . override_id ( aws_request_id = aws_request_id ) else : logging . CloudCanvasLogger . init_instance ( aws_request_id = aws_request_id , output = sys . stdout ) module_name = event . get ( 'module' , None ) if not module_name : raise ValueError ( 'No "module" property was provided n the event object.' ) function_name = event . get ( 'function' , None ) if not function_name : raise ValueError ( 'No "function" property was provided in the event object.' ) print ( 'request id {} has module {} and function {}' . format ( aws_request_id , module_name , function_name ) ) module = importlib . import_module ( 'api.' + module_name ) function = getattr ( module , function_name , None ) if not function : raise ValueError ( 'The module "{}" does not have an "{}" attribute.' . format ( module_name , function_name ) ) if not callable ( function ) : raise ValueError ( 'The module "{}" attribute "{}" is not a function.' . format ( module_name , function_name ) ) if not hasattr ( function , 'is_dispatch_handler' ) : raise ValueError ( 'The module "{}" function "{}" is not a service dispatch handler.' . format ( module_name , function_name ) ) parameters = event . get ( 'parameters' , { } ) __check_function_parameters ( function , parameters ) # The request parameters are logged after finding the handler function since that's where the logging filters are defined. # Request logging is also after the request validation so that the logging filters don't have to know how to filter unexpected data. filtered_parameters = __apply_logging_filter ( function , parameters ) print ( 'dispatching function {} with parameters {}' . format ( 'api.{}.{}' . format ( module_name , function_name ) , filtered_parameters ) ) request = Request ( event , context ) result = { } try : result = function ( request , * * parameters ) except Exception as e : error_message = 'CloudCanvas_request_id : {} failed with {}' . format ( aws_request_id , message ( e ) ) raise ClientError ( error_message ) from e try : result [ "CloudCanvas_request_id" ] = aws_request_id except Exception as e : print ( 'Failed to add request id to request result {}' . format ( message ( e ) ) ) filtered_result = __apply_logging_filter ( function , result ) print ( 'returning result {}' . format ( filtered_result ) ) return result