AWS powertools documentation change
Summary
Added documentation for HttpResolverLocal development resolver with explicit warnings about production use, examples, and Swagger UI integration
Security assessment
The change adds documentation for a development-only resolver with clear warnings against production use. While this highlights security implications of misuse, there's no evidence of addressing a specific existing security vulnerability.
Diff
diff --git a/powertools/python/latest/core/event_handler/api_gateway.md b/powertools/python/latest/core/event_handler/api_gateway.md index a34bdca67..7f6bc8e7e 100644 --- a//powertools/python/latest/core/event_handler/api_gateway.md +++ b//powertools/python/latest/core/event_handler/api_gateway.md @@ -55,0 +56 @@ Metrics + * Http Resolver (Local Development) @@ -229,0 +231 @@ Table of contents + * Http Resolver (Local Development) @@ -566,0 +569 @@ Resolver | AWS service +**`HttpResolverLocal`** | Local development with ASGI servers @@ -1508,0 +1512,202 @@ Example payload delivered to the handler +#### Http Resolver (Local Development)¶ + +Local Development Only + +`HttpResolverLocal` is intended for local development and testing only. The API may change in future releases. **Do not use in production environments.** + +When developing locally, you can use `HttpResolverLocal` to run your API with any ASGI server like [uvicorn](https://www.uvicorn.org/). It implements the [ASGI specification](https://asgi.readthedocs.io/), is lightweight with no external dependencies, and the same code works on any compute platform, including Lambda. + +If your Lambda is behind [Lambda Web Adapter](https://github.com/awslabs/aws-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 + +| + + + pip install uvicorn + + +---|--- + +Basic UsageWith Validation & SwaggerException Handling + + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + +| + + + from aws_lambda_powertools.event_handler import HttpResolverLocal + + app = HttpResolverLocal() + + + @app.get("/hello/<name>") + def hello(name: str): + return {"message": f"Hello, {name}!"} + + + # Lambda handler - same code works in Lambda + handler = app + + +---|--- + +Run locally: `uvicorn app:app --reload` + + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + +| + + + from pydantic import BaseModel + + from aws_lambda_powertools.event_handler import HttpResolverLocal + + + class User(BaseModel): + name: str + age: int + + + app = HttpResolverLocal(enable_validation=True) + + app.enable_swagger( + title="My API", + version="1.0.0", + ) + + + @app.post("/users") + def create_user(user: User) -> dict: + return {"id": "123", "user": user.model_dump()} + + + handler = app + + +---|--- + +Access Swagger UI at `http://localhost:8000/swagger` + + + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 + 18 + 19 + 20 + 21 + 22 + 23 + 24 + 25 + 26 + 27 + 28 + 29 + 30 + 31 + 32 + 33 + 34 + 35 + 36 + +| + + + from aws_lambda_powertools.event_handler import HttpResolverLocal, Response + + app = HttpResolverLocal() + + + class NotFoundError(Exception): + def __init__(self, resource: str): + self.resource = resource + + + @app.exception_handler(NotFoundError) + def handle_not_found_error(exc: NotFoundError): + return Response( + status_code=404, + content_type="application/json", + body={"error": "Not Found", "resource": exc.resource}, + ) + + + @app.not_found + def handle_not_found(exc: Exception): + return Response( + status_code=404, + content_type="application/json", + body={"error": "Route not found", "path": app.current_event.path}, + ) +