HttpResolver is an ASGI-compatible resolver that lets you run your Powertools application with any ASGI server like uvicorn. It implements the ASGI specification, is lightweight with no external dependencies, and works seamlessly with Lambda or any environment that speaks HTTP.
If your Lambda is behind Lambda Web Adapter or any other HTTP proxy that speaks the HTTP protocol, it works seamlessly.
All existing resolver features work out of the box: routing, middleware, validation, OpenAPI/Swagger, CORS, exception handling, and more.
Install uvicorn:
1
pipinstalluvicorn
1 2 3 4 5 6 7 8 9101112
fromaws_lambda_powertools.event_handlerimportHttpResolverapp=HttpResolver()@app.get("/hello/<name>")defhello(name:str):return{"message":f"Hello, {name}!"}# Lambda handler - same code works in Lambdahandler=app
fromaws_lambda_powertools.event_handlerimportHttpResolver,Responseapp=HttpResolver()classNotFoundError(Exception):def__init__(self,resource:str):self.resource=resource@app.exception_handler(NotFoundError)defhandle_not_found_error(exc:NotFoundError):returnResponse(status_code=404,content_type="application/json",body={"error":"Not Found","resource":exc.resource},)@app.not_founddefhandle_not_found(exc:Exception):returnResponse(status_code=404,content_type="application/json",body={"error":"Route not found","path":app.current_event.path},)@app.get("/users/<user_id>")defget_user(user_id:str):ifuser_id=="0":raiseNotFoundError(f"User {user_id}")return{"user_id":user_id}handler=app