Ever wanted to easily system test your lambda function, or perhaps run it locally in a sane manner? All this without writing any weird hacks?
Then let me tell you about
lambdaserver-python!
This is a webserver to use for locally running lambda functions in a live-like environment while being able to easily test multiple scenarios in a containerized environment (building upon the glorious lambci/docker-lambda).
What's neat is you can use your regular testing suite for testing your lambda by simply making requests with an event and maybe some environment variables and then get back any return values/errors and the logs outputted by the lambda function.
Check the /example folder for examples on how to use it in different scenarios. Or maybe check out how the system tests are set up? Or here below? Up to you.
Step by step:
/example folder).zip into the container when the container is runninglocalhost:5000/invoke/<your_lambda_handler_here>The API specification for how to make requests to the server can be found in ./lambdaserver/api-specification.yaml
In code please!
# The path to the packaged .zip file is ./my-packages
# and the package name is lambda_package.zip
docker run \
-v "${PWD}/my-packages:/packages" \
-p 5000:80 \
-e "PACKAGE_NAME=lambda_package.zip" \
-it --rm bambora-dkr.jfrog.io/lambdaserver-python3.7
To pass in environment variables to the lambda function, simply provide these as per the spec in the request body!
There are a couple different environment variables that might be interesting when using the lambda server though, they are the the following:
${PACKAGE_FOLDER}=/packagesThe folder in which the lambda package(s) (.zip files) should be mounted in into.
Defaults to /packages
${PACKAGE_NAME}=pkg.zipThe name of the package that was passed in which should be run and unzipped.
Defaults to pkg.zip
${RUN_IN_WATCH_MODE}="0"Boolean value for whether to run in watch mode, which basically means that the .zip file in /packages won't be unzipped.
This variable should be used when mounting in the application code straight into /var/task for a watch-mode like experience.
Defaults to "0"
${EXEC_BEFORE}=""Bash script to run before starting the server. Example usage would be to install third-party dependencies into an external folder when running in test mode, since installing them next to the application code will completely ruin your local file tree.
See an example of this in the /example folder.
Of course, it's code after all.
The biggest potential issue is that the code being run in this image is run as root instead of a low privilege user. Please submit a PR with a fix if this is something you want.
Please don't. The purpose of this tool is to use it for running your lambdas locally for black-box testing.
Content type
Image
Digest
Size
297.8 MB
Last updated
over 6 years ago
docker pull akino1976/lambda-server