GitHub - Valian/python-lambda-local-server: Easier local development of Python AWS lambda functions.
Repository navigation
python-lambda-local-serverPublic
About
Easier local development of Python AWS lambda functions.
hub.docker.com/r/valian/python-lambda-local-server/Topics
lambda python python-lambda-local serverlessResources
Readme ActivityStars
3 starsWatchers
2 watchingForks
1 fork Report repositoryBranches
Tags
Go to Branches page Go to Tags page
Latest commit
History
15 Commits
View commit history for this file.
Folders and files
| Name | Name | Last commit message | Last commit date |
|---|---|---|---|
| example | example | ||
| pictures | pictures | ||
| .dockerignore | .dockerignore | ||
| .gitignore | .gitignore | ||
| Dockerfile | Dockerfile | ||
| README.md | README.md | ||
| app.py | app.py | ||
| docker-compose.yml | docker-compose.yml | ||
| index.html | index.html | ||
| requirements.in | requirements.in | ||
| requirements.py | requirements.py | ||
| requirements.txt | requirements.txt | ||
Repository files navigation
python-lambda-local-server
A Docker image to help with development of a local AWS lambda Python functions. Based on the lambci/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
Usage
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 to http://localhost:8080 . You should see a simple web UI for testing your lambda function.
Assuming that you have your lambda entrypoint in lambda.py and handler is named handler, you should
type 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.
Example
First, clone this repository:
git clone https://github.com/Valian/python-lambda-local-server cd 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
Web UI usage
Go to http://localhost:8080 . You should see something like this:
Specify file, handler and event and click Submit event.
It invokes handler and prints execution logs and return value.
Api gateway tab automatically formats event to an AWS API Gateway format:
Console example
You can of course use curl 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"
}
TODO
- Add support for
Serverless.ymlfile - Cleanup code, better error codes
- Support for chaining lambda calls either through AWS SDK or API endpoint
License
MIT
About
Easier local development of Python AWS lambda functions.
hub.docker.com/r/valian/python-lambda-local-server/