You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Please use a newly created virtualenv of Python 3.7+.
Installation
Within virtualenv, run the following command.
$ pip install python-lambda-local
This will install the package with namepython-lambda-local in the virtualenv.Now you can use the commandpython-lambda-local to run your AWS Lambda function written in Python on your own machine.
Usage as a shell command
Runpython-lambda-local -h to see the help.
usage: python-lambda-local [-h] [-l LIBRARY_PATH] [-f HANDLER_FUNCTION] [-t TIMEOUT] [-a ARN_STRING] [-v VERSION_NAME] [-e ENVIRONMENT_VARIABLES] [--version] FILE EVENTRun AWS Lambda function written in Python on local machine.positional arguments: FILE lambda function file name EVENT event data file nameoptional arguments: -h, --help show this help message and exit -l LIBRARY_PATH, --library LIBRARY_PATH path of 3rd party libraries -f HANDLER_FUNCTION, --function HANDLER_FUNCTION lambda function handler name, default: "handler" -t TIMEOUT, --timeout TIMEOUT seconds until lambda function timeout, default: 3 -a ARN_STRING, --arn-string ARN_STRING ARN string for lambda function -v VERSION_NAME, --version-name VERSION_NAME lambda function version name -e ENVIRONMENT_VARIABLES, --environment-variables ENVIRONMENT_VARIABLES path to flat json file with environment variables --version print the version of python-lambda-local and exit
The handler's code is intest.py and the function name of the handler ishandler.The source depends on 3rd party libraryrx and it is installed in the directorylib.The test event in json format is inevent.json file.
Installingrx library inlib/
pip install --target lib rx==1.6.1
Content oftest.py:
from __future__importprint_functionfromrximportObservabledefhandler(event,context):xs=Observable.from_(range(event['answer']))ys=xs.to_blocking()zs= (x*xforxinysifx%7==0)forxinzs:print(x)
Content ofevent.json:
{"answer":42}
Run the lambda function
Within the project root directory, you can run the lambda function with the following command