簡體   English   中英

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

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

我正在使用“python-lambda-local”在本地測試一個簡單的python程序。 但是低於例外情況,盡管在 AWS env 上運行時它工作正常。

下面是代碼。

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

使用以下命令運行它 -
$python-lambda-local -f lambda_handler lambda_handler.py event.json

環境 - 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