original_docstring:  Decorator that will check that event.get('body') has keys, then add a map of selected keys
      to kwargs.
  
      Args:
          required (iterable): Required body keys
          optional (iterable): Optional body keys
  
      Returns:
          handler (func): a lambda handler function that is namespace aware
      
docstring: Decorator that will check that event.get('body') has keys, then add a map of selected keys
  to kwargs.
docstring_tokens: Decorator that will check that event . get ( ' body ' ) has keys then add a map of selected keys to kwargs .
code: def body(required=None, optional=None, error=None):
      """ Decorator that will check that event.get('body') has keys, then add a map of selected keys
      to kwargs.
  
      Args:
          required (iterable): Required body keys
          optional (iterable): Optional body keys
  
      Returns:
          handler (func): a lambda handler function that is namespace aware
      """
      def body_handler(handler):
          def handler_wrapper(event, context, **kwargs):
              try:
                  event_body = json.loads(event.get('body'))
              except json.JSONDecodeError:
                  return {'statusCode': 400, 'body': error or 'Invalid event.body: cannot decode json.'}
  
              body_required = {k: event_body.get(k) for k in (required if required else {})}
              if not all((v is not None for v in body_required.values())):
                  logger.error(f'There is a required key in [{required}] missing from event.body [{event_body}].')
                  return {'statusCode': 400, 'body': error or 'Invalid event.body: missing required key.'}
  
              body_optional = {k: event_body.get(k) for k in (optional if optional else {})}
  
              handler_body = {}
              handler_body.update(**body_required, **body_optional)
              kwargs['body'] = handler_body
  
              return handler(event, context, **kwargs)
  
          return handler_wrapper
  
      return body_handler
code_tokens: def body ( required = None , optional = None , error = None ) : def body_handler ( handler ) : def handler_wrapper ( event , context , ** kwargs ) : try : event_body = json . loads ( event . get ( 'body' ) ) except json . JSONDecodeError : return { 'statusCode' : 400 , 'body' : error or 'Invalid event.body: cannot decode json.' } body_required = { k : event_body . get ( k ) for k in ( required if required else { } ) } if not all ( ( v is not None for v in body_required . values ( ) ) ) : logger . error ( f'There is a required key in [{required}] missing from event.body [{event_body}].' ) return { 'statusCode' : 400 , 'body' : error or 'Invalid event.body: missing required key.' } body_optional = { k : event_body . get ( k ) for k in ( optional if optional else { } ) } handler_body = { } handler_body . update ( ** body_required , ** body_optional ) kwargs [ 'body' ] = handler_body return handler ( event , context , ** kwargs ) return handler_wrapper return body_handler
short_docstring: Decorator that will check that event.get('body') has keys, then add a map of selected keys
  to kwargs.
short_docstring_tokens: Decorator that will check that event . get ( ' body ' ) has keys then add a map of selected keys to kwargs .
comment: """ Decorator that will check that event.get('body') has keys, then add a map of selected keys
      to kwargs.
  
      Args:
          required (iterable): Required body keys
          optional (iterable): Optional body keys
  
      Returns:
          handler (func): a lambda handler function that is namespace aware
      """