Given a function and event context, detect signature and execute, returning any result.
(app_function, event, context)
| 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 | """ |
no outgoing calls