Skip to content

Commit 8806cad

Browse files
sdangolsvozza
andauthored
docs(event-handler): added documentation for support for HTTP API, ALB and FURL (#4795)
Co-authored-by: Stefano Vozza <[email protected]>
1 parent d2e0fcc commit 8806cad

File tree

4 files changed

+82
-10
lines changed

4 files changed

+82
-10
lines changed

docs/features/event-handler/rest.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ status: new
77
!!! warning "Feature status"
88
This feature is under active development and may undergo significant changes. We recommend using it in non-critical workloads and [providing feedback](https://github.com/aws-powertools/powertools-lambda-typescript/issues/new/choose){target="_blank"} to help us improve it.
99

10-
Event handler for Amazon API Gateway REST <!-- and HTTP APIs, Application Loader Balancer (ALB), Lambda Function URLs, and VPC Lattice -->.
10+
Event handler for Amazon API Gateway REST and HTTP APIs, Application Loader Balancer (ALB), and Lambda Function URLs<!--, and VPC Lattice -->.
1111

1212
## Key Features
1313

14-
* Lightweight routing to reduce boilerplate for API Gateway REST (HTTP API, ALB and Lambda Function URLs coming soon)
14+
* Lightweight routing to reduce boilerplate for API Gateway REST/HTTP API, ALB and Lambda Function URLs.
1515
* Built-in middleware engine for request/response transformation (validation coming soon).
1616
* Works with micro function (one or a few routes) and monolithic functions (see [Considerations](#considerations)).
1717

@@ -27,24 +27,45 @@ npm install @aws-lambda-powertools/event-handler
2727

2828
### Required resources
2929

30-
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.
30+
The event handler works with different types of events. It can process events from API Gateway REST APIs, HTTP APIs, ALB, Lambda Function URLs, and will soon support VPC Lattice as well.
31+
32+
You must have an existing integration configured to invoke your Lambda function depending on what you are using:
33+
34+
| Integration | Documentation |
35+
| ------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
36+
| API Gateway REST API | [Proxy integration](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html){target="_blank"} |
37+
| API Gateway HTTP API | [Proxy integration](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html){target="_blank"} |
38+
| Application Load Balancer | [ALB configuration](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html){target="_blank"} |
39+
| Lambda Function URL | [Function URL configuration](https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html){target="_blank"} |
3140

3241
<!-- In case of using [VPC Lattice](https://docs.aws.amazon.com/lambda/latest/dg/services-vpc-lattice.html){target="_blank"}, you must have a service network configured to invoke your Lambda function. -->
3342

34-
This is the sample infrastructure for API Gateway <!-- and Lambda Function URLs --> we are using for the examples in this documentation. There is no additional permissions or dependencies required to use this utility.
43+
This is the sample infrastructure for the different integrations we are using for the examples in this documentation. There is no additional permissions or dependencies required to use this utility.
3544

3645
??? "See Infrastructure as Code (IaC) examples"
37-
=== "API Gateway SAM Template"
46+
=== "API Gateway REST API SAM Template"
47+
48+
```yaml title="AWS Serverless Application Model (SAM) example"
49+
--8<-- "examples/snippets/event-handler/rest/templates/api_gateway_rest_api.yml"
50+
```
51+
52+
=== "API Gateway HTTP API SAM Template"
3853

3954
```yaml title="AWS Serverless Application Model (SAM) example"
40-
--8<-- "examples/snippets/event-handler/rest/templates/api_gateway.yml"
55+
--8<-- "examples/snippets/event-handler/rest/templates/api_gateway_http_api.yml"
56+
```
57+
58+
=== "Lambda Function URL SAM Template"
59+
60+
```yaml title="AWS Serverless Application Model (SAM) example"
61+
--8<-- "examples/snippets/event-handler/rest/templates/lambda_furl.yml"
4162
```
4263

4364
### Route events
4465

45-
Before you start defining your routes, it's important to understand how the event handler works with different types of events. The event handler can process events from API Gateway REST APIs, and will soon support HTTP APIs, ALB, Lambda Function URLs, and VPC Lattice as well.
66+
When a request is received, the event handler automatically detects the event type and converts it into a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request){target="_blank"} object.
4667

47-
When a request is received, the event handler will automatically convert the event into a [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request) object and give you access to the current request context, including headers, query parameters, and request body, as well as path parameters via typed arguments.
68+
You get access to headers, query parameters, request body, and path parameters via typed arguments. The response type is determined automatically based on the event.
4869

4970
#### Response auto-serialization
5071

@@ -71,6 +92,9 @@ For your convenience, when you return a JavaScript object from your route handle
7192
--8<-- "examples/snippets/event-handler/rest/samples/gettingStarted_serialization.json"
7293
```
7394

95+
!!! tip "Automatic response format transformation"
96+
The event handler automatically ensures the correct response format is returned based on the event type received. For example, if your handler returns an API Gateway v1 proxy response but processes an ALB event, we'll automatically transform it into an ALB-compatible response. This allows you to swap integrations with little to no code changes.
97+
7498
### Dynamic routes
7599

76100
You can use `/todos/:todoId` to configure dynamic URL paths, where `:todoId` will be resolved at runtime.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
AWSTemplateFormatVersion: "2010-09-09"
2+
Transform: AWS::Serverless-2016-10-31
3+
Description: Hello world event handler API Gateway HTTP API
4+
5+
Globals:
6+
HttpApi:
7+
CorsConfiguration:
8+
AllowOrigins:
9+
- https://example.com
10+
AllowHeaders:
11+
- Content-Type
12+
- Authorization
13+
- X-Amz-Date
14+
MaxAge: 300
15+
16+
Function:
17+
Timeout: 5
18+
MemorySize: 256
19+
Runtime: nodejs22.x
20+
Tracing: Active
21+
Environment:
22+
Variables:
23+
POWERTOOLS_LOG_LEVEL: INFO
24+
POWERTOOLS_SERVICE_NAME: hello
25+
26+
Resources:
27+
ApiFunction:
28+
Type: AWS::Serverless::Function
29+
Properties:
30+
Handler: index.handler
31+
CodeUri: hello_world
32+
Description: API handler function
33+
Events:
34+
AnyApiEvent:
35+
Type: HttpApi
36+
Properties:
37+
Path: /{proxy+}
38+
Method: ANY
39+
GetAllTodos:
40+
Type: HttpApi
41+
Properties:
42+
Path: /todos
43+
Method: GET
44+
GetTodoById:
45+
Type: HttpApi
46+
Properties:
47+
Path: /todos/{todo_id}
48+
Method: GET

examples/snippets/event-handler/rest/templates/api_gateway.yml renamed to examples/snippets/event-handler/rest/templates/api_gateway_rest_api.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AWSTemplateFormatVersion: "2010-09-09"
22
Transform: AWS::Serverless-2016-10-31
3-
Description: Hello world event handler API Gateway
3+
Description: Hello world event handler API Gateway REST API
44

55
Globals:
66
Api:

examples/snippets/event-handler/rest/templates/lambda_furl.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
AWSTemplateFormatVersion: "2010-09-09"
22
Transform: AWS::Serverless-2016-10-31
3-
Description: Hello world event handler API Gateway
3+
Description: Hello world event handler Lambda Function URL
44

55
Globals:
66
Function:

0 commit comments

Comments
 (0)