A package with flask-like syntax for routing requests from an AWS ALB in Lambda
Project description
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__
}
)
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
File details
Details for the file LambdaALBRouter-0.2.tar.gz
.
File metadata
- Download URL: LambdaALBRouter-0.2.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using 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.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ddd1413b05d36083fe3b6c7a77b5d4d15f2382359a2d3e0c33b1cc4e60dd616 |
|
MD5 | 0ac401133a042daef96b7495c2b5d9e7 |
|
BLAKE2b-256 | 9cc8a217230420bf69345af727ae711f3ed32cf99f0fc65f6233b597a9a1214b |
File details
Details for the file LambdaALBRouter-0.2-py3-none-any.whl
.
File metadata
- Download URL: LambdaALBRouter-0.2-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using 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.6.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 581641e03df71730841981c7f16d9ab13d2bdd2f9585d93c361fad5da7f76039 |
|
MD5 | 26ee27e5a78523ef360971c1eeaf907f |
|
BLAKE2b-256 | a0ddb038abd51ad403708915edf87f3f59eaa8f83b055e3a91a14fa006f6983a |