Package: lbz
LambdalizatorIf you want to work with Lambdalizator in Python 3.8, consider using version0.5.19.AWS Lambda Toolbox inspired by Flask. Currently supporting:REST APIEvent API (AWS Event Bridge)Lambda APIAuthenticationLambdalizator can automatically read the value of theAuthenticationHTTP header and transform it
into the User object that is available as a part of the request. TheAuthenticationheader 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 eitherALLOWED_PUBLIC_KEYSorALLOWED_AUDIENCESenvironment variables.ConfigurationLambdalizator can be configured using the following environment variables:Authorization configurationALLOWED_PUBLIC_KEYS- a list of public keys that can be used for decoding auth tokens send in theAuthenticationandAuthorizationheaders. If you are using Cognito, you can use public keys from:https://cognito-idp.{youraws 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 theAuthenticationandAuthorizationheaders. 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 (likecognito:) in the
auth token will have the prefix removed. Defaults to False (set as "0" or "1").Lambdalizator configurationLOGGING_LEVEL- log level used in the application. Defaults to INFO.LBZ_DEBUG_MODE- set lbz to work in debug mode.CORS_HEADERS- a list of additional headers that should be supported.CORS_ORIGIN- a list of allowed origins that should be supported.AWS related configurationAWS_LAMBDA_FUNCTION_NAME- defined by AWS Lambda environment used ATM only in EventAPIEVENTS_BUS_NAME- expected by EventAPI Event Bridge Events Bus Name. Defaults to Lambda name
taken from AWS_LAMBDA_FUNCTION_NAME and extended with-event-busHello World Example:1. Define resource# simple_resource.pyfromlbz.routerimportadd_routefromlbz.responseimportResponsefromlbz.resourceimportResourceclassHelloWorld(Resource):@add_route("/",method="GET")deflist(self):returnResponse({"message":"HelloWorld"})2. Define handler# simple_resource.pyfromlbz.exceptionsimportLambdaFWExceptionfromsimple_resourceimportHelloWorlddefhandle(event,context):try:returnHelloWorld(event)()exceptExceptionaserr:returnLambdaFWException().get_response(context.aws_request_id).to_dict()3. Create dev Server 🖥️# simple_resource_dev.pyfromlbz.dev.serverimportMyDevServerfromsimple_resource.simple_resourceimportHelloWorldif__name__=='__main__':server=MyDevServer(acls=HelloWorld,port=8001)server.run()4. Don't forget to unit test# pytest simple_resource_test.pyfromlbz.dev.testimportClientfromsimple_resourceimportHelloWorldclassTestHelloWorld:defsetup_method(self)->None:# pylint: disable=attribute-defined-outside-initself.client=Client(resource=HelloWorld)deftest_filter_queries_all_active_when_no_params(self)->None:data=self.client.get("/").to_dict()["body"]assertdata=='{"message":"HelloWorld"}'5. Authenticate it 💂# simple_auth/simple_resource.pyfromlbz.routerimportadd_routefromlbz.responseimportResponsefromlbz.resourceimportResourcefromlbz.authzimportauthorizationclassHelloWorld(Resource):_name="helloworld"@authorization()@add_route("/",method="GET")deflist(self,restrictions=None):returnResponse({"message":f"Hello,{self.request.user.username}!"})DocumentationWIPChangelogRelease ChangelogsContributionWe are always happy to have new contributions.
We have marked issues good for anyone looking to get started
Please take a look at ourContribution guidelines.