You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As routes are now split in their own files, you can optionally instruct `Router` to inject a prefix for all routes during registration.
917
+
In the previous example, `users.py` routes had a `/users` prefix. This might grow over time and become repetitive.
918
918
919
-
In the previous example, `users.py` routes had a `/users`prefix. We could remove `/users` from all route definitions, and then set `include_router(users.router, prefix="/users")`in the `app.py`.
919
+
When necessary, you can set a prefix when including a router object. This means you could remove `/users` prefix in `users.py` altogether.
920
920
921
921
=== "app.py"
922
922
@@ -931,8 +931,9 @@ In the previous example, `users.py` routes had a `/users` prefix. We could remov
931
931
app = ApiGatewayResolver()
932
932
app.include_router(users.router, prefix="/users") # prefix '/users' to any route in `users.router`
@router.get("/") # /users, when we set the prefix in app.py
952
953
def get_users() -> Dict:
@@ -961,7 +962,9 @@ In the previous example, `users.py` routes had a `/users` prefix. We could remov
961
962
962
963
#### Sample larger layout
963
964
964
-
Below is an example project layout where we have Users routes similar to the previous example, and health check route - We use ALB to demonstrate the UX remains the same.
965
+
!!! info "We use ALB to demonstrate that the UX remains the same"
966
+
967
+
Below is an example project layout where we have Users routes similar to the previous example, and health check route.
965
968
966
969
Note that this layout optimizes for code sharing and for those familiar with Python modules. This means multiple functions will share the same `CodeUri` and package, though they are only built once.
967
970
@@ -1026,7 +1029,7 @@ Note that this layout optimizes for code sharing and for those familiar with Pyt
1026
1029
HealthPath:
1027
1030
Type: Api
1028
1031
Properties:
1029
-
Path: /health/status
1032
+
Path: /status
1030
1033
Method: GET
1031
1034
UserPath:
1032
1035
Type: Api
@@ -1055,22 +1058,22 @@ Note that this layout optimizes for code sharing and for those familiar with Pyt
1055
1058
from aws_lambda_powertools import Logger, Tracer
1056
1059
from aws_lambda_powertools.event_handler import ApiGatewayResolver
1057
1060
from aws_lambda_powertools.event_handler.api_gateway import ProxyEventType
1058
-
from aws_lambda_powertools.logging.correlation_paths import API_GATEWAY_HTTP
1061
+
from aws_lambda_powertools.logging.correlation_paths import ALB
1059
1062
from aws_lambda_powertools.utilities.typing import LambdaContext
0 commit comments