Given a function and event context, detect signature and execute, returning any result.
(app_function, event, context)
| 613 | |
| 614 | @staticmethod |
| 615 | def run_function(app_function, event, context): |
| 616 | """ |
| 617 | Given a function and event context, |
| 618 | detect signature and execute, returning any result. |
| 619 | """ |
| 620 | args, varargs, keywords, defaults, _, _, _ = inspect.getfullargspec(app_function) |
| 621 | num_args = len(args) |
| 622 | if num_args == 0: |
| 623 | result = app_function(event, context) if varargs else app_function() |
| 624 | elif num_args == 1: |
| 625 | result = app_function(event, context) if varargs else app_function(event) |
| 626 | elif num_args == 2: |
| 627 | result = app_function(event, context) |
| 628 | else: |
| 629 | raise RuntimeError( |
| 630 | "Function signature is invalid. Expected a function that accepts at most " "2 arguments or varargs." |
| 631 | ) |
| 632 | return result |
| 633 | |
| 634 | def get_function_for_aws_event(self, record): |
| 635 | """ |
no outgoing calls