UNPKG

907 BPlain TextView Raw
1#!/usr/bin/env python2.7
2
3import argparse
4import json
5import sys
6from time import time
7from importlib import import_module
8
9parser = argparse.ArgumentParser(
10 prog='invoke',
11 description='Runs a Lambda entry point (handler) with an optional event',
12)
13
14parser.add_argument('handler_path',
15 help=('Path to the module containing the handler function,'
16 ' omitting ".py". IE: "path/to/module"'))
17
18parser.add_argument('handler_name', help='Name of the handler function')
19
20if __name__ == '__main__':
21 args = parser.parse_args()
22
23 # this is needed because you need to import from where you've executed sls
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))