Skip to content

Commit 8486e03

Browse files
authored
Merge pull request HDE#7 from HDE/master
release v0.1.3
2 parents b35cd61 + 0bba8f8 commit 8486e03

File tree

6 files changed

+34
-14
lines changed

6 files changed

+34
-14
lines changed

CHANGELOG.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ Version 0.1.2
1212
-------------
1313

1414
- Add more commandline options.
15+
16+
Version 0.1.3
17+
-------------
18+
19+
- Exit with non-zero code when execution of function fails.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# python-lambda-local
22

33
[![Join the chat at https://gitter.im/HDE/python-lambda-local](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/HDE/python-lambda-local?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
4+
[![wercker status](https://app.wercker.com/status/04f5bc5b7de3d5c6f13eb5b871035226/s "wercker status")](https://app.wercker.com/project/bykey/04f5bc5b7de3d5c6f13eb5b871035226)
45

56
Run lambda function on local machine
67

lambda_local/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,12 @@
1414

1515
def main():
1616
args = parse_args()
17-
try:
18-
p = Process(target=run, args=(args,))
19-
p.start()
20-
p.join()
21-
except:
22-
e = sys.exc_info()
23-
print(e[1])
17+
18+
p = Process(target=run, args=(args,))
19+
p.start()
20+
p.join()
21+
22+
sys.exit(p.exitcode)
2423

2524

2625
def parse_args():

lambda_local/main.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
urllib3.disable_warnings()
2525

2626

27+
ERR_TYPE_EXCEPTION = 0
28+
ERR_TYPE_TIMEOUT = 1
29+
30+
EXITCODE_ERR = 1
31+
32+
2733
def run(args):
2834
e = event.read_event(args.event)
2935
c = context.Context(args.timeout, args.arn_string, args.version_name)
@@ -40,10 +46,7 @@ def run(args):
4046
logger.info("START RequestId: {}".format(request_id))
4147

4248
start_time = timeit.default_timer()
43-
try:
44-
result = execute(func, e, c)
45-
except TimeoutException as te:
46-
result = te
49+
result, err_type = execute(func, e, c)
4750
end_time = timeit.default_timer()
4851

4952
logger.info("END RequestId: {}".format(request_id))
@@ -57,6 +60,9 @@ def run(args):
5760
logger.info("REPORT RequestId: {}\tDuration: {}".format(
5861
request_id, duration))
5962

63+
if err_type is not None:
64+
sys.exit(EXITCODE_ERR)
65+
6066

6167
def load_lib(path):
6268
sys.path.append(os.path.abspath(path))
@@ -75,17 +81,21 @@ def load(request_id, path, function_name):
7581

7682

7783
def execute(func, event, context):
84+
err_type = None
85+
7886
try:
7987
with time_limit(context.timeout):
8088
result = func(event, context.activate())
8189
except TimeoutException as err:
82-
raise err
90+
result = err
91+
err_type = ERR_TYPE_TIMEOUT
8392
except:
8493
err = sys.exc_info()
8594
result = json.dumps({
8695
"errorMessage": str(err[1]),
8796
"stackTrace": traceback.extract_tb(err[2]),
8897
"errorType": err[0].__name__
8998
}, indent=4, separators=(',', ': '))
99+
err_type = ERR_TYPE_EXCEPTION
90100

91-
return result
101+
return result, err_type

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def run_tests(self):
2626
sys.exit(pytest.main(self.test_args))
2727

2828

29-
version = "0.1.2"
29+
version = "0.1.3"
3030

3131
setup(name="python-lambda-local",
3232
version=version,

wercker.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ box: python:2.7-slim
22

33
build:
44
steps:
5+
- script:
6+
name: virtualenv install
7+
code: |
8+
pip install virtualenv
9+
510
- virtualenv:
611
name: setup virtual environment
712
install_wheel: true # Enable wheel to speed up builds (experimental)

0 commit comments

Comments
 (0)