Skip to content

Commit 200c801

Browse files
committed
docs(api-gateway): add new API mapping support
1 parent c9bb647 commit 200c801

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

docs/core/event_handler/api_gateway.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,49 @@ Additionally, we provide pre-defined errors for the most popular ones such as HT
435435
return app.resolve(event, context)
436436
```
437437

438+
439+
### Custom Domain API Mappings
440+
441+
When using Custom Domain API Mappings feature, you must use **`strip_prefixes`** param in the `ApiGatewayResolver` constructor.
442+
443+
Scenario: You have a custom domain `api.mydomain.dev` and set an API Mapping `payment` to forward requests to your Payments API, the path argument will be `/payment/<your_actual_path>`.
444+
445+
This will lead to a HTTP 404 despite having your Lambda configured correctly. See the example below on how to account for this change.
446+
447+
448+
=== "app.py"
449+
450+
```python hl_lines="7"
451+
from aws_lambda_powertools import Logger, Tracer
452+
from aws_lambda_powertools.logging import correlation_paths
453+
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
454+
455+
tracer = Tracer()
456+
logger = Logger()
457+
app = ApiGatewayResolver(strip_prefixes=["/payment"])
458+
459+
@app.get("/subscriptions/<subscription>")
460+
@tracer.capture_method
461+
def get_subscription(subscription):
462+
return {"subscription_id": subscription}
463+
464+
@logger.inject_lambda_context(correlation_id_path=correlation_paths.API_GATEWAY_REST)
465+
@tracer.capture_lambda_handler
466+
def lambda_handler(event, context):
467+
return app.resolve(event, context)
468+
```
469+
470+
=== "sample_request.json"
471+
472+
```json
473+
{
474+
"resource": "/subscriptions/{subscription}",
475+
"path": "/payment/subscriptions/123",
476+
"httpMethod": "GET",
477+
...
478+
}
479+
```
480+
438481
## Advanced
439482

440483
### CORS

0 commit comments

Comments
 (0)