简体   繁体   English

使用 python-lambda-local 在本地使用 Python AWS Lambda 函数

[英]Python AWS Lambda function locally using python-lambda-local

I was testing one simple python program locally using "python-lambda-local".我正在使用“python-lambda-local”在本地测试一个简单的python程序。 But getting below exceptions, though its working fine when running on AWS env.但是低于例外情况,尽管在 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 $python-lambda-local -f lambda_handler lambda_handler.py event.json

Env - Windows10 Python - 3.6 Exception -环境 - Windows10 Python - 3.6 异常 -

[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 中修复了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM