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
Copy file name to clipboardExpand all lines: docs/core/event_handler/api_gateway.md
+38
Original file line number
Diff line number
Diff line change
@@ -287,6 +287,8 @@ You can use `/path/{dynamic_value}` when configuring dynamic URL paths. This all
287
287
}
288
288
```
289
289
290
+
#### Nested routes
291
+
290
292
You can also nest paths as configured earlier in [our sample infrastructure](#required-resources): `/{message}/{name}`.
291
293
292
294
=== "app.py"
@@ -323,6 +325,42 @@ You can also nest paths as configured earlier in [our sample infrastructure](#re
323
325
}
324
326
```
325
327
328
+
#### Catch-all routes
329
+
330
+
!!! note "We recommend having explicit routes whenever possible; use catch-all routes sparingly"
331
+
332
+
You can use a regex string to handle an arbitrary number of paths within a request, for example `.+`.
333
+
334
+
You can also combine nested paths with greedy regex to catch in between routes.
335
+
336
+
!!! warning "We will choose the more explicit registered route that match incoming event"
337
+
338
+
=== "app.py"
339
+
340
+
```python hl_lines="5"
341
+
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
342
+
343
+
app = ApiGatewayResolver()
344
+
345
+
@app.get(".+")
346
+
def catch_any_route_after_any():
347
+
return {"path_received": app.current_event.path}
348
+
349
+
def lambda_handler(event, context):
350
+
return app.resolve(event, context)
351
+
```
352
+
353
+
=== "sample_request.json"
354
+
355
+
```json
356
+
{
357
+
"resource": "/any/route/should/work",
358
+
"path": "/any/route/should/work",
359
+
"httpMethod": "GET",
360
+
...
361
+
}
362
+
```
363
+
326
364
### Accessing request details
327
365
328
366
By integrating with [Data classes utilities](../../utilities/data_classes.md){target="_blank"}, you have access to request details, Lambda context and also some convenient methods.
0 commit comments