MCPcopy Index your code
hub / github.com/Miserlou/Zappa / handler

Method handler

zappa/handler.py:338–605  ·  view source on GitHub ↗

An AWS Lambda function which parses specific API Gateway input into a WSGI request, feeds it to our WSGI app, processes the response, and returns that back to the API Gateway.

(self, event, context)

Source from the content-addressed store, hash-verified

336 return self.settings.COGNITO_TRIGGER_MAPPING.get(trigger)
337
338 def handler(self, event, context):
339 """
340 An AWS Lambda function which parses specific API Gateway input into a
341 WSGI request, feeds it to our WSGI app, processes the response, and returns
342 that back to the API Gateway.
343
344 """
345 settings = self.settings
346
347 # If in DEBUG mode, log all raw incoming events.
348 if settings.DEBUG:
349 logger.debug('Zappa Event: {}'.format(event))
350
351 # Set any API Gateway defined Stage Variables
352 # as env vars
353 if event.get('stageVariables'):
354 for key in event['stageVariables'].keys():
355 os.environ[str(key)] = event['stageVariables'][key]
356
357 # This is the result of a keep alive, recertify
358 # or scheduled event.
359 if event.get('detail-type') == 'Scheduled Event':
360
361 whole_function = event['resources'][0].split('/')[-1].split('-')[-1]
362
363 # This is a scheduled function.
364 if '.' in whole_function:
365 app_function = self.import_module_and_get_function(whole_function)
366
367 # Execute the function!
368 return self.run_function(app_function, event, context)
369
370 # Else, let this execute as it were.
371
372 # This is a direct command invocation.
373 elif event.get('command', None):
374
375 whole_function = event['command']
376 app_function = self.import_module_and_get_function(whole_function)
377 result = self.run_function(app_function, event, context)
378 print("Result of %s:" % whole_function)
379 print(result)
380 return result
381
382 # This is a direct, raw python invocation.
383 # It's _extremely_ important we don't allow this event source
384 # to be overridden by unsanitized, non-admin user input.
385 elif event.get('raw_command', None):
386
387 raw_command = event['raw_command']
388 exec(raw_command)
389 return
390
391 # This is a Django management command invocation.
392 elif event.get('manage', None):
393
394 from django.core import management
395

Calls 10

run_functionMethod · 0.95
_process_exceptionMethod · 0.95
get_django_wsgiFunction · 0.85
merge_headersFunction · 0.85
create_wsgi_requestFunction · 0.85
common_logFunction · 0.85