Skip to content

Commit cb3bc5b

Browse files
committed
chore(docs): add documentation for Lambda Functoin URLs
1 parent aca525c commit cb3bc5b

File tree

6 files changed

+706
-27
lines changed

6 files changed

+706
-27
lines changed

docs/core/event_handler/api_gateway.md

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ title: REST API
33
description: Core utility
44
---
55

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.
77

88
## Key Features
99

10-
* Lightweight routing to reduce boilerplate for API Gateway REST/HTTP API and ALB
10+
* Lightweight routing to reduce boilerplate for API Gateway REST/HTTP API, ALB and Lambda Function URLs.
1111
* Support for CORS, binary and Gzip compression, Decimals JSON encoding and bring your own JSON serializer
1212
* Built-in integration with [Event Source Data Classes utilities](../../utilities/data_classes.md){target="_blank"} for self-documented event schema
1313

@@ -18,23 +18,31 @@ Event handler for Amazon API Gateway REST and HTTP APIs, and Application Loader
1818

1919
### Required resources
2020

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.
2222

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.
2424

2525
???+ info "There is no additional permissions or dependencies required to use this utility."
2626

27-
```yaml title="AWS Serverless Application Model (SAM) example"
28-
--8<-- "examples/event_handler_rest/sam/template.yaml"
29-
```
27+
=== "API Gateway SAM Template"
28+
29+
```yaml title="AWS Serverless Application Model (SAM) example"
30+
--8<-- "examples/event_handler_rest/sam/template.yaml"
31+
```
32+
33+
=== "Lambda Function URL SAM Template"
34+
35+
```yaml title="AWS Serverless Application Model (SAM) example"
36+
--8<-- "examples/event_handler_lambda_function_url/sam/template.yaml"
37+
```
3038

3139
### Event Resolvers
3240

3341
Before you decorate your functions to handle a given path and HTTP method(s), you need to initialize a resolver.
3442

3543
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.
3644

37-
For resolvers, we provide: `APIGatewayRestResolver`, `APIGatewayHttpResolver`, and `ALBResolver`.
45+
For resolvers, we provide: `APIGatewayRestResolver`, `APIGatewayHttpResolver`, `ALBResolver`, and `LambdaFunctionUrlResolver` .
3846

3947
???+ info
4048
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
8795
--8<-- "examples/event_handler_rest/src/getting_started_alb_api_resolver.py"
8896
```
8997

98+
#### Lambda Function URL
99+
100+
When using an [AWS Lambda Function URL](https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html), you can use `LambdaFunctionUrlResolver`.
101+
102+
=== "getting_started_lambda_function_url_resolver.py"
103+
104+
```python hl_lines="5 11" title="Using Lambda Function URL resolver"
105+
--8<-- "examples/event_handler_lambda_function_url/src/getting_started_lambda_function_url_resolver.py"
106+
```
107+
108+
=== "getting_started_lambda_function_url_resolver.json"
109+
110+
```json hl_lines="4-5" title="Example payload delivered to the handler"
111+
--8<-- "examples/event_handler_lambda_function_url/src/getting_started_lambda_function_url_resolver.json"
112+
```
113+
90114
### Dynamic routes
91115

92116
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
270294

271295
#### Pre-flight
272296

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.
274298

275299
For convenience, we automatically handle that for you as long as you [setup CORS in the constructor level](#cors).
276300

@@ -338,6 +362,7 @@ Like `compress` feature, the client must send the `Accept` header with the corre
338362

339363
???+ warning
340364
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.
341366

342367
=== "binary_responses.py"
343368

@@ -380,7 +405,7 @@ This will enable full tracebacks errors in the response, print request and respo
380405

381406
### Custom serializer
382407

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.
384409

385410
```python hl_lines="35 40" title="Using a custom JSON serializer for responses"
386411
--8<-- "examples/event_handler_rest/src/custom_serializer.py"
@@ -501,7 +526,7 @@ A micro function means that your final code artifact will be different to each f
501526

502527
**Downsides**
503528

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.
505530
* 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.
506531
* **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,
507532
your development, building, deployment tooling need to accommodate the distinct layout.

0 commit comments

Comments
 (0)