LambdaALBRouter
LambdaALBRouter is a small package with flask-like syntax for routing requests from an AWS ALB in Lambda. It parses out all relavent information from the triggering event and passes it through to a matching registered route. With exceptions handled and turned into json responses, utilities for quickly exiting and returning json it is very easy to make quick APIs with ALB-fronted Lambdas in AWS.
Currently there is nothing implemented for handling templates or returning HTML, but that will be added in the future. Runtime data is stored in a separate class and not stored in the instance of ALBRouter to allow that instance to be a global variable (and cached between lambda executions) without running into caching issues.
Installing
pip install -U LambdaALBRouter
Example
from LambdaALBRouter import router, abort, response
app = router.ALBRouter()
def lambda_handler(event, _context):
return app.process_lambda_alb_event(event)
@app.route("/")
def hello():
return response("Hello world!")
@app.route("/hello/<user>")
def hello_user(user):
return response(f"Hello {user}!")
@app.route("/update/<user>", route_methods=["POST"])
def update_user(user, context):
input_data = context.data
query_string = context.query_string
request_headers = context.request_headers
if not "something" in input_data.keys():
abort(400, "Missing required input 'something'")
# Update user in a database...
return response(
{
"message": f"Updated {user}!",
"context": context.__dict__
}
)
Metadata
Release files for LambdaALBRouter 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| LambdaALBRouter-0.1.tar.gz | 7.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| LambdaALBRouter-0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 15.7 kB
Release files / LambdaALBRouter-0.1.tar.gz
| Download URL | LambdaALBRouter-0.1.tar.gz |
|---|---|
| Size | 7.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1cc6f09300381751f33444e071e3b0b2089e96401b75ed5aa4f31f484958852e
|
|
BLAKE2b-256 checksum How to use checksums |
f2997f83428e89c4a740991b7f2ca23ec4cfd3586b9c008a9af2bd4c4098366c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
|
Release files / LambdaALBRouter-0.1-py3-none-any.whl
| Download URL | LambdaALBRouter-0.1-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
01180d8434b44eac5b941abf007cd184cf28670d6f3d2da8eb59f14c4d4f8d65
|
|
BLAKE2b-256 checksum How to use checksums |
e8627bbd80479a987856a711733b831fd40d19995d7f97802a279dd9e35c4833
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.3
|