Universal entry point for Docker images containing WSGI apps for the AWS Lambda.
Project description
Lambdarado puts together:
-
A Flask app written in Python
-
A Docker image that contains the app code and dependencies
-
AWS Lambda + AWS Gateway to run the app in the AWS
-
Werkzeug to test app locally
It runs the relevant code depending on where it runs.
On the local computer, it runs
the a debug server, serving requests to
127.0.0.1 with your app. You can start it directly (python3 main.py) or from a
container (docker run ...) to test the app.
In the AWS Cloud the requests are handled with the same app, but in a
different way. Lambdarado creates
a handler,
that is compatible with the combination of API Gateway + Lambda.
Install
$ pip3 install lambdarado
Configure
Dockerfile:
FROM public.ecr.aws/lambda/python:3.8
# ... here should be the code that creates the image ...
ENTRYPOINT ["python", "main.py"]
You build the image as usual,
but the ENTRYPOINT is just a call to a .py file in the project root.
And there is no CMD.
main.py
from lambdarado import start
def get_app():
# this function must return WSGI app, e.g. Flask
from my_app_module import app
return app
start(get_app)
When starting the Lambda function instance, the get_app method will run once,
but the main.py module will be imported twice. Make sure that the app is only created
when get_app is called, not when main.py is imported.
In other words, simply running python3 main.py without calling start should
NOT do anything heavy and probably should not even declare or import the app.
Run
Local debug server
Running shell command on development machine:
$ python3 main.py
This will start Werkzeug server listening to http://127.0.0.1:5000.
Local debug server in Docker
Command-line:
$ docker run -p 5005:5000 docker-image-name
This will start Werkzeug server listening to http://0.0.0.0:5000 (inside the docker). The server is accessible as http://127.0.0.1:5005 from the development (host) machine.
Production server on AWS Lambda
After deploying the same image as a Lambda function, it will serve the requests
to the AWS Gateway with your app.
- You should connect the AWS Gateway to your Lambda function. For the function
to receive all HTTP requests, you may need to redirect the
/{proxy+}route to the function and makelambda:InvokeFunctionpolicy less restrictive
Under the hood:
- The awslambdaric will receive requests from and send requests to the Lambda service
- The apig_wsgi will translate requests
received by
awslambdaricfrom the AWS Gateway. So your application doesn't have to handle calls from the gateway directly. For the application, requests will look like normal HTTP
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file lambdarado-2.3.0.post2.tar.gz.
File metadata
- Download URL: lambdarado-2.3.0.post2.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d5b515b32ad4381fe4cfa684aa6251f468ee0e53f421c3362bb958c9b6f33738
|
|
| MD5 |
9c9f0ffc5881e6d4eb376aa3e27887af
|
|
| BLAKE2b-256 |
3fe5cb299e920374c497c359c9cb5b8234c5525ae3cedc61385ea96bd16d5861
|
File details
Details for the file lambdarado-2.3.0.post2-py3-none-any.whl.
File metadata
- Download URL: lambdarado-2.3.0.post2-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f6cdc03712d1de31064b5366a6cb9d874588eac27f5861499e2b9a103d3a60f3
|
|
| MD5 |
0ce22c02df437d3170b5520a64090c6f
|
|
| BLAKE2b-256 |
3e2e1f226d3a18bc125f0d58a36c278caf2d6e1e589c31216f0950ed3dd31559
|