{"id":13813910,"url":"https://github.com/HDE/python-lambda-local","last_synced_at":"2025-05-15T01:32:07.635Z","repository":{"id":1872212,"uuid":"44359250","full_name":"HDE/python-lambda-local","owner":"HDE","description":"Run AWS Lambda function on local machine","archived":false,"fork":false,"pushed_at":"2024-07-16T10:07:51.000Z","size":93,"stargazers_count":305,"open_issues_count":11,"forks_count":35,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-11-14T14:47:43.478Z","etag":null,"topics":["aws-lambda","local-machine","python-lambda-local","python37","python38","python39","virtualenv"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/HDE.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.txt","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-10-16T03:06:10.000Z","updated_at":"2024-10-30T16:21:24.000Z","dependencies_parsed_at":"2024-08-04T04:04:55.620Z","dependency_job_id":null,"html_url":"https://github.com/HDE/python-lambda-local","commit_stats":{"total_commits":119,"total_committers":11,"mean_commits":"10.818181818181818","dds":0.4453781512605042,"last_synced_commit":"6b88d11bf74c839fd0f8039fe8690a5e451a655f"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HDE%2Fpython-lambda-local","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HDE%2Fpython-lambda-local/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HDE%2Fpython-lambda-local/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HDE%2Fpython-lambda-local/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HDE","download_url":"https://codeload.github.com/HDE/python-lambda-local/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225319392,"owners_count":17455764,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws-lambda","local-machine","python-lambda-local","python37","python38","python39","virtualenv"],"created_at":"2024-08-04T04:01:35.713Z","updated_at":"2024-11-19T08:31:13.262Z","avatar_url":"https://github.com/HDE.png","language":"Python","readme":"# python-lambda-local\n\n[![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\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n[![Github Actions status](https://github.com/HDE/python-lambda-local/actions/workflows/execute_tests.yml/badge.svg)](https://github.com/HDE/python-lambda-local/actions/)\n[![PyPI version](https://badge.fury.io/py/python-lambda-local.svg)](https://badge.fury.io/py/python-lambda-local)\n\nRun lambda function on local machine\n\n## Prepare development environment\n\nPlease use a newly created virtualenv of Python 3.7+.\n\n## Installation\n\nWithin virtualenv, run the following command.\n\n``` bash\n$ pip install python-lambda-local\n```\n\nThis will install the package with name `python-lambda-local` in the virtualenv.\nNow you can use the command `python-lambda-local` to run your AWS Lambda function written in Python on your own machine.\n\n## Usage as a shell command\n\nRun `python-lambda-local -h` to see the help.\n\n```\nusage: python-lambda-local [-h] [-l LIBRARY_PATH] [-f HANDLER_FUNCTION]\n                           [-t TIMEOUT] [-a ARN_STRING] [-v VERSION_NAME]\n                           [-e ENVIRONMENT_VARIABLES] [--version]\n                           FILE EVENT\n\nRun AWS Lambda function written in Python on local machine.\n\npositional arguments:\n  FILE                  lambda function file name\n  EVENT                 event data file name\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -l LIBRARY_PATH, --library LIBRARY_PATH\n                        path of 3rd party libraries\n  -f HANDLER_FUNCTION, --function HANDLER_FUNCTION\n                        lambda function handler name, default: \"handler\"\n  -t TIMEOUT, --timeout TIMEOUT\n                        seconds until lambda function timeout, default: 3\n  -a ARN_STRING, --arn-string ARN_STRING\n                        ARN string for lambda function\n  -v VERSION_NAME, --version-name VERSION_NAME\n                        lambda function version name\n  -e ENVIRONMENT_VARIABLES, --environment-variables ENVIRONMENT_VARIABLES\n                        path to flat json file with environment variables\n  --version             print the version of python-lambda-local and exit\n```\n\n### Prepare development directory\n\n#### Project directory structure\n\nSuppose your project directory is like this:\n\n```\n├── event.json\n├── lib\n│   ├── rx\n│   │   ├── abstractobserver.py\n│   │   ├── ... (package content of rx)\n...\n│   │       └── testscheduler.py\n│   └── Rx-1.6.1.dist-info\n│       ├── DESCRIPTION.rst\n│       ├── METADATA\n│       ├── metadata.json\n│       ├── pbr.json\n│       ├── RECORD\n│       ├── top_level.txt\n│       ├── WHEEL\n│       └── zip-safe\n└── test.py\n```\n\nThe handler's code is in `test.py` and the function name of the handler is `handler`.\nThe source depends on 3rd party library `rx` and it is installed in the directory `lib`.\nThe test event in json format is in `event.json` file.\n\n#### Installing `rx` library in `lib/`\n\n``` bash\npip install --target lib rx==1.6.1\n```\n\n#### Content of `test.py`:\n\n``` python\nfrom __future__ import print_function\nfrom rx import Observable\n\n\ndef handler(event, context):\n    xs = Observable.from_(range(event['answer']))\n    ys = xs.to_blocking()\n    zs = (x*x for x in ys if x % 7 == 0)\n    for x in zs:\n        print(x)\n```\n\n#### Content of `event.json`:\n\n``` json\n{\n  \"answer\": 42\n}\n```\n\n#### Run the lambda function\n\nWithin the project root directory, you can run the lambda function with the following command\n\n```\npython-lambda-local -l lib/ -f handler -t 5 test.py event.json\n```\n\nThe output will be like:\n\n```\n[root - INFO - 2018-11-20 17:10:53,352] Event: {'answer': 42}\n[root - INFO - 2018-11-20 17:10:53,352] START RequestId: 3c8e6db4-886a-43da-a1c7-5e6f715de531 Version: \n0\n49\n196\n441\n784\n1225\n[root - INFO - 2018-11-20 17:10:53,359] END RequestId: 3c8e6db4-886a-43da-a1c7-5e6f715de531\n[root - INFO - 2018-11-20 17:10:53,360] REPORT RequestId: 3c8e6db4-886a-43da-a1c7-5e6f715de531\tDuration: 2.17 ms\n[root - INFO - 2018-11-20 17:10:53,360] RESULT:\nNone\n```\n\n## Usage as a library\n\n### API signature\n\n``` python\ncall(func, event, context, environment_variables={})\n```\n\nCall a handler function `func` with given `event`, `context` and custom `environment_variables`.\n\n### Sample\n\n1. Make sure the 3rd party libraries used in the AWS Lambda function can be imported.\n\n``` bash\npip install rx==1.6.1\n```\n\n2. To call the lambda function above with your python code:\n\n``` python\nfrom lambda_local.main import call\nfrom lambda_local.context import Context\n\nimport test\n\nevent = {\n    \"answer\": 42\n}\ncontext = Context(5)\n\nif __name__ == '__main__':\n    call(test.handler, event, context)\n```\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHDE%2Fpython-lambda-local","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FHDE%2Fpython-lambda-local","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FHDE%2Fpython-lambda-local/lists"}