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
+37-11
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,11 @@ title: REST API
3
3
description: Core utility
4
4
---
5
5
6
-
Event handler for Amazon API Gateway REST and HTTP APIs, and Application Loader Balancer (ALB).
6
+
Event handler for Amazon API Gateway REST and HTTP APIs, Application Loader Balancer (ALB), and Lambda Function URLs.
7
7
8
8
## Key Features
9
9
10
-
* Lightweight routing to reduce boilerplate for API Gateway REST/HTTP APIand ALB
10
+
* Lightweight routing to reduce boilerplate for API Gateway REST/HTTP API, ALB and Lambda Function URLs.
11
11
* Support for CORS, binary and Gzip compression, Decimals JSON encoding and bring your own JSON serializer
12
12
* Built-in integration with [Event Source Data Classes utilities](../../utilities/data_classes.md){target="_blank"} for self-documented event schema
13
13
@@ -18,23 +18,31 @@ Event handler for Amazon API Gateway REST and HTTP APIs, and Application Loader
18
18
19
19
### Required resources
20
20
21
-
You must have an existing [API Gateway Proxy integration](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html){target="_blank"} or [ALB](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html){target="_blank"} configured to invoke your Lambda function.
21
+
If you're using any API Gateway integration, you must have an existing [API Gateway Proxy integration](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html){target="_blank"} or [ALB](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html){target="_blank"} configured to invoke your Lambda function.
22
22
23
-
This is the sample infrastructure for API Gateway we are using for the examples in this documentation.
23
+
This is the sample infrastructure for API Gateway and Lambda Function URLs we are using for the examples in this documentation.
24
24
25
25
???+ info "There is no additional permissions or dependencies required to use this utility."
26
26
27
-
```yaml title="AWS Serverless Application Model (SAM) example"
Before you decorate your functions to handle a given path and HTTP method(s), you need to initialize a resolver.
34
42
35
43
A resolver will handle request resolution, including [one or more routers](#split-routes-with-router), and give you access to the current event via typed properties.
36
44
37
-
For resolvers, we provide: `APIGatewayRestResolver`, `APIGatewayHttpResolver`, and `ALBResolver`.
45
+
For resolvers, we provide: `APIGatewayRestResolver`, `APIGatewayHttpResolver`, `ALBResolver`, and `LambdaFunctionUrlResolver`.
38
46
39
47
???+ info
40
48
We will use `APIGatewayRestResolver` as the default across examples.
@@ -87,6 +95,22 @@ When using Amazon Application Load Balancer (ALB) to front your Lambda functions
You can use `/todos/<todo_id>` to configure dynamic URL paths, where `<todo_id>` will be resolved at runtime.
@@ -270,7 +294,7 @@ This will ensure that CORS headers are always returned as part of the response w
270
294
271
295
#### Pre-flight
272
296
273
-
Pre-flight (OPTIONS) calls are typically handled at the API Gateway level as per [our sample infrastructure](#required-resources), no Lambda integration necessary. However, ALB expects you to handle pre-flight requests.
297
+
Pre-flight (OPTIONS) calls are typically handled at the API Gateway or Lambda Function URL level as per [our sample infrastructure](#required-resources), no Lambda integration is necessary. However, ALB expects you to handle pre-flight requests.
274
298
275
299
For convenience, we automatically handle that for you as long as you [setup CORS in the constructor level](#cors).
276
300
@@ -339,6 +363,8 @@ Like `compress` feature, the client must send the `Accept` header with the corre
339
363
???+ warning
340
364
This feature requires API Gateway to configure binary media types, see [our sample infrastructure](#required-resources) for reference.
341
365
366
+
???+ note
367
+
Lambda Function URLs handle binary media types automatically.
342
368
=== "binary_responses.py"
343
369
344
370
```python hl_lines="14 20"
@@ -380,7 +406,7 @@ This will enable full tracebacks errors in the response, print request and respo
380
406
381
407
### Custom serializer
382
408
383
-
You can instruct API Gateway handler to use a custom serializer to best suit your needs, for example take into account Enums when serializing.
409
+
You can instruct event handler to use a custom serializer to best suit your needs, for example take into account Enums when serializing.
384
410
385
411
```python hl_lines="35 40" title="Using a custom JSON serializer for responses"
@@ -501,7 +527,7 @@ A micro function means that your final code artifact will be different to each f
501
527
502
528
**Downsides**
503
529
504
-
***Upfront investment**. You need custom build tooling to bundle assets, including [C bindings for runtime compatibility](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html){target="_blank"}. `Operations become more elaborate — you need to standardize tracing labels/annotations, structured logging, and metrics to pinpoint root causes.
530
+
***Upfront investment**. You need custom build tooling to bundle assets, including [C bindings for runtime compatibility](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html){target="_blank"}. Operations become more elaborate — you need to standardize tracing labels/annotations, structured logging, and metrics to pinpoint root causes.
505
531
* Engineering discipline is necessary for both approaches. Micro-function approach however requires further attention in consistency as the number of functions grow, just like any distributed system.
506
532
***Harder to share code**. Shared code must be carefully evaluated to avoid unnecessary deployments when that changes. Equally, if shared code isn't a library,
507
533
your development, building, deployment tooling need to accommodate the distinct layout.
0 commit comments