- Notifications
You must be signed in to change notification settings - Fork1
Easier local development of Python AWS lambda functions.
Valian/python-lambda-local-server
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Docker image to help with development of a local AWS lambda Python functions.Based on thelambci/lambda image.Created, because I haven't found an easy way to run lambda function locally.
Features:
- Automatically installs packages from requirements.txt during startup
- Mirrored AWS Lambda environment thanks to lambci images
- Code is reloaded for each submitted event
- Available simple Web UI for better workflow
Go to directory with your lambda Python code. Next, run this command:
docker run -it \ -p 8080:8080 \ -v lambda-packages-cache:/packages/ \ # if you want to persist packages cache -v $PWD:/var/task/ \ valian/python-lambda-local-server
It should automatically install packages from your requirements.txt and start web sever written in aiohttp.To see web UI, head tohttp://localhost:8080. You should see a simple web UI for testing your lambda function.
Assuming that you have your lambda entrypoint inlambda.py
and handler is namedhandler
, you shouldtype it into respective inputs. Next, add JSON body that should be passed to the function as an event, and press 'Submit event'.Result and logs should be visible on the right panel after a moment.
First, clone this repository:
git clone https://github.com/Valian/python-lambda-local-servercd python-lambda-local-server
Next, start server with a proper volume mounted:
docker run -it \ -p 8080:8080 \ -v$PWD/example:/var/task/ \ valian/python-lambda-local-server
Go tohttp://localhost:8080. You should see something like this:
Specify file, handler and event and clickSubmit event
.It invokes handler and prints execution logs and return value.
Api gateway tab automatically formats event to an AWS API Gateway format:
You can of course usecurl
to submit events. Start sever and type:
curl -XPOST localhost:8080 -d'{"event": {"url": "https://example.com"}, "file": "handler.handler"}'{"stdout": {"statusCode": 200,"url":"https://example.com/" },"stderr":"START RequestId: b1891caf-c22b-4ce6-8639-e74862adae30 Version:$LATEST\nINFO:root:Starting request\nINFO:root:Request done, status code: 200\nEND RequestId: b1891caf-c22b-4ce6-8639-e74862adae30\nREPORT RequestId: b1891caf-c22b-4ce6-8639-e74862adae30 Duration: 803 ms Billed Duration: 900 ms Memory Size: 1536 MB Max Memory Used: 23 MB\n"}
- Add support for
Serverless.yml
file - Cleanup code, better error codes
- Support for chaining lambda calls either through AWS SDK or API endpoint
MIT
About
Easier local development of Python AWS lambda functions.
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.