1 |
|
2 |
|
3 | import argparse
|
4 | import json
|
5 | import sys
|
6 | from time import time
|
7 | from importlib import import_module
|
8 |
|
9 | parser = argparse.ArgumentParser(
|
10 | prog='invoke',
|
11 | description='Runs a Lambda entry point (handler) with an optional event',
|
12 | )
|
13 |
|
14 | parser.add_argument('handler_path',
|
15 | help=('Path to the module containing the handler function,'
|
16 | ' omitting ".py". IE: "path/to/module"'))
|
17 |
|
18 | parser.add_argument('handler_name', help='Name of the handler function')
|
19 |
|
20 | if __name__ == '__main__':
|
21 | args = parser.parse_args()
|
22 |
|
23 |
|
24 | sys.path.append('.')
|
25 |
|
26 | module = import_module(args.handler_path.replace('/', '.'))
|
27 | handler = getattr(module, args.handler_name)
|
28 |
|
29 | event = json.load(sys.stdin)
|
30 | result = handler(event)
|
31 | sys.stdout.write(json.dumps(result, indent=4))
|