MCPcopy Create free account
hub / github.com/Miserlou/Zappa / run_function

Method run_function

zappa/handler.py:265–286  ·  view source on GitHub ↗

Given a function and event context, detect signature and execute, returning any result.

(app_function, event, context)

Source from the content-addressed store, hash-verified

263
264 @staticmethod
265 def run_function(app_function, event, context):
266 """
267 Given a function and event context,
268 detect signature and execute, returning any result.
269 """
270 # getargspec does not support python 3 method with type hints
271 # Related issue: https://github.com/Miserlou/Zappa/issues/1452
272 if hasattr(inspect, "getfullargspec"): # Python 3
273 args, varargs, keywords, defaults, _, _, _ = inspect.getfullargspec(app_function)
274 else: # Python 2
275 args, varargs, keywords, defaults = inspect.getargspec(app_function)
276 num_args = len(args)
277 if num_args == 0:
278 result = app_function(event, context) if varargs else app_function()
279 elif num_args == 1:
280 result = app_function(event, context) if varargs else app_function(event)
281 elif num_args == 2:
282 result = app_function(event, context)
283 else:
284 raise RuntimeError("Function signature is invalid. Expected a function that accepts at most "
285 "2 arguments or varargs.")
286 return result
287
288 def get_function_for_aws_event(self, record):
289 """

Callers 3

handlerMethod · 0.95
test_run_functionMethod · 0.80

Calls

no outgoing calls

Tested by 2

test_run_functionMethod · 0.64