I was testing one simple python program locally using "python-lambda-local". But getting below exceptions, though its working fine when running on AWS env.
Below is the Code.
import os
import json
def lambda_handler(event, context):
what_to_print = os.environ.get("what_to_print")
how_many_times = int(os.environ.get("how_many_times"))
# make sure what_to_print and how_many_times values exist
if what_to_print and how_many_times > 0:
for i in range(0, how_many_times):
# formatted string literals are new in Python 3.6
print(f"what_to_print: {what_to_print}.")
return what_to_print
return None
Run this using below command -
$python-lambda-local -f lambda_handler lambda_handler.py event.json
Env - Windows10 Python - 3.6 Exception -
[root — INFO — 2018–01–13 22:14:22,138] Event: {‘what_to_print1’: ‘Hello’, ‘how_many_times1’: ‘2’}
[root — INFO — 2018–01–13 22:14:22,138] START RequestId: 7c602d94–7fa4–45ae-91db-674877eba4ef
Process Process-1:
Traceback (most recent call last):
File “c:\program files\python36\lib\site-packages\lambda_local\main.py”, line 91, in execute
with time_limit(context.timeout):
File “c:\program files\python36\lib\contextlib.py”, line 82, in __enter__
return next(self.gen)
File “c:\program files\python36\lib\site-packages\lambda_local\timeout.py”, line 18, in time_limit
signal.signal(signal.SIGALRM, signal_handler)
AttributeError: module ‘signal’ has no attribute ‘SIGALRM’
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File “c:\program files\python36\lib\multiprocessing\process.py”, line 249, in _bootstrap
self.run()
File “c:\program files\python36\lib\multiprocessing\process.py”, line 93, in run
self._target(*self._args, **self._kwargs)
File “c:\program files\python36\lib\site-packages\lambda_local\main.py”, line 53, in run
result, err_type = execute(func, e, c)
File “c:\program files\python36\lib\site-packages\lambda_local\main.py”, line 102, in execute
}, indent=4, separators=(‘,’, ‘: ‘))
File “c:\program files\python36\lib\json\__init__.py”, line 238, in dumps
**kw).encode(obj)
File “c:\program files\python36\lib\json\encoder.py”, line 201, in encode
chunks = list(chunks)
File “c:\program files\python36\lib\json\encoder.py”, line 430, in _iterencode
yield from _iterencode_dict(o, _current_indent_level)
File “c:\program files\python36\lib\json\encoder.py”, line 404, in _iterencode_dict
yield from chunks
File “c:\program files\python36\lib\json\encoder.py”, line 325, in _iterencode_list
yield from chunks
File “c:\program files\python36\lib\json\encoder.py”, line 437, in _iterencode
o = _default(o)
File “c:\program files\python36\lib\json\encoder.py”, line 180, in default
o.__class__.__name__)
TypeError: Object of type ‘FrameSummary’ is not JSON serializable
Process finished with exit code 1
它应该已经在 python-lambda-local 的 v0.1.6 中修复了。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.