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
Metadata
Release files for lambdarado 2.3.0.post2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| lambdarado-2.3.0.post2.tar.gz | 6.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| lambdarado-2.3.0.post2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 14.5 kB
Release files / lambdarado-2.3.0.post2.tar.gz
| Download URL | lambdarado-2.3.0.post2.tar.gz |
|---|---|
| Size | 6.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d5b515b32ad4381fe4cfa684aa6251f468ee0e53f421c3362bb958c9b6f33738
|
|
BLAKE2b-256 checksum How to use checksums |
3fe5cb299e920374c497c359c9cb5b8234c5525ae3cedc61385ea96bd16d5861
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|
Release files / lambdarado-2.3.0.post2-py3-none-any.whl
| Download URL | lambdarado-2.3.0.post2-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6cdc03712d1de31064b5366a6cb9d874588eac27f5861499e2b9a103d3a60f3
|
|
BLAKE2b-256 checksum How to use checksums |
3e2e1f226d3a18bc125f0d58a36c278caf2d6e1e589c31216f0950ed3dd31559
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is 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
|