Skip to main content

Lambdalizator


Stable version Python versions Code style: black Imports: isort Checked with mypy Downloads
If you want to work with Lambdalizator in Python 3.8, consider using version 0.5.19.
If you want to work with Lambdalizator in Python 3.9, consider using version 0.6.7.

AWS Lambda Toolbox inspired by Flask. Currently supporting:

  • REST API
  • Event API (AWS Event Bridge)
  • Lambda API

Authentication

Lambdalizator can automatically read the value of the Authentication HTTP header and transform it into the User object that is available as a part of the request. The Authentication header must contain a JWT token that will be verified using one of the configured public keys (see Configuration below). The User object will have properties corresponding to the key-value pairs from the token's data.

To enable authentication provide a value for either ALLOWED_PUBLIC_KEYS or ALLOWED_AUDIENCES environment variables.

Configuration

Lambdalizator can be configured using the following environment variables:

Authorization configuration

  • ALLOWED_PUBLIC_KEYS - a list of public keys that can be used for decoding auth tokens send in the Authentication and Authorization headers. If you are using Cognito, you can use public keys from: https://cognito-idp.{your aws region}.amazonaws.com/{your pool id}/.well-known/jwks.json.
  • ALLOWED_AUDIENCES - a list of audiences that will be used for verifying the JWTs send in the Authentication and Authorization headers. It should be a comma-separated list of strings, e.g. aud1,aud2. If not set, any audience will be considered valid.
  • ALLOWED_ISS - allowed issuer of JWT - Security feature. If not set, issuer will not be checked.
  • AUTH_REMOVE_PREFIXES - if enabled, all fields starting with a prefix (like cognito:) in the auth token will have the prefix removed. Defaults to False (set as "0" or "1").

Lambdalizator configuration

  • LOGGING_LEVEL - log level used in the application. Defaults to INFO.
  • CORS_HEADERS - a list of additional headers that should be supported.
  • CORS_ORIGIN - a list of allowed origins that should be supported.
  • AWS_LAMBDA_FUNCTION_NAME - defined by AWS Lambda environment used ATM only in EventAPI
  • EVENTS_BUS_NAME - expected by EventAPI Event Bridge Events Bus Name. Defaults to Lambda name taken from AWS_LAMBDA_FUNCTION_NAME and extended with -event-bus

Hello World Example:

1. Define resource

# simple_resource.py

from lbz.router import add_route
from lbz.response import Response
from lbz.resource import Resource

class HelloWorld(Resource):

    @add_route("/", method="GET")
    def list(self):
        return Response({"message": "HelloWorld"})
        

2. Define handler

# simple_resource.py

from lbz.exceptions import LambdaFWException

from simple_resource import HelloWorld


def handle(event, context):
    try:
        return HelloWorld(event)()
    except Exception as err:
        return LambdaFWException().get_response(context.aws_request_id).to_dict()

3. Create dev Server 🖥️

# simple_resource_dev.py

from lbz.dev.server import MyDevServer

from simple_resource.simple_resource import HelloWorld

if __name__ == '__main__':
    server = MyDevServer(acls=HelloWorld, port=8001)
    server.run()

4. Don't forget to unit test

# pytest simple_resource_test.py
from lbz.dev.test import Client

from simple_resource import HelloWorld

class TestHelloWorld:
    def setup_method(self) -> None:
        # pylint: disable=attribute-defined-outside-init
        self.client = Client(resource=HelloWorld)

    def test_filter_queries_all_active_when_no_params(self) -> None:
        data = self.client.get("/").to_dict()["body"]
        assert data == '{"message":"HelloWorld"}'

5. Authenticate it 💂

# simple_auth/simple_resource.py

from lbz.router import add_route
from lbz.response import Response
from lbz.resource import Resource
from lbz.authz import authorization


class HelloWorld(Resource):
    _name = "helloworld"

    @authorization()
    @add_route("/", method="GET")
    def list(self, restrictions=None):
        return Response({"message": f"Hello, {self.request.user.username} !"})
     

Documentation

WIP

Changelog

Release Changelogs

Contribution

We are always happy to have new contributions. We have marked issues good for anyone looking to get started Please take a look at our Contribution guidelines.

Metadata

Release files for lbz 0.10.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for lbz 0.10.3
File Size Uploaded Provenance Actions
lbz-0.10.3.tar.gz 44.4 kB Without provenance Details for lbz-0.10.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for lbz 0.10.3
File Interpreter ABI Platform Actions
lbz-0.10.3-py3-none-any.whl Python 3 none any Details for lbz-0.10.3-py3-none-any.whl

Total release size: 80.8 kB

Release files / lbz-0.10.3.tar.gz

Download URL lbz-0.10.3.tar.gz
Size 44.4 kB
Tags Source
SHA-256 checksum
How to use checksums
fe8a327fb4f4769025736b822238f21105654e6a3bb4d60d46a178846713bdf9
BLAKE2b-256 checksum
How to use checksums
1a5f34b204362ce31bcafd8576baa3a1b648b7013b2fce982d619506bc64cd3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Release files / lbz-0.10.3-py3-none-any.whl

Download URL lbz-0.10.3-py3-none-any.whl
Size 36.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
18ba24ba35f5fc466e8e99764ee75c3332817319cba3fe5b07e23ed19d2707c9
BLAKE2b-256 checksum
How to use checksums
6eb7f4e10970664ce550a0e6cb303f07328fd7ae16696fd0b559b36bdf385c2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.10.22

Security for lbz 0.10.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.10.3 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page