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
+36-11Lines changed: 36 additions & 11 deletions
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
When using an [AWS Lambda Function URL](https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html), you can use `LambdaFunctionUrlResolver`.
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 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
@@ -338,6 +362,7 @@ Like `compress` feature, the client must send the `Accept` header with the corre
338
362
339
363
???+ warning
340
364
This feature requires API Gateway to configure binary media types, see [our sample infrastructure](#required-resources) for reference.
365
+
For Lambda Function URLs, no additional configuration is necessary.
341
366
342
367
=== "binary_responses.py"
343
368
@@ -380,7 +405,7 @@ This will enable full tracebacks errors in the response, print request and respo
380
405
381
406
### Custom serializer
382
407
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.
408
+
You can instruct an event handler to use a custom serializer to best suit your needs, for example take into account Enums when serializing.
384
409
385
410
```python hl_lines="35 40" title="Using a custom JSON serializer for responses"
@@ -501,7 +526,7 @@ A micro function means that your final code artifact will be different to each f
501
526
502
527
**Downsides**
503
528
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.
529
+
***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
530
* 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
531
***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
532
your development, building, deployment tooling need to accommodate the distinct layout.
0 commit comments