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/features/event-handler/rest.md
+32-8Lines changed: 32 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,11 @@ status: new
7
7
!!! warning "Feature status"
8
8
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.
9
9
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 -->.
11
11
12
12
## Key Features
13
13
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.
15
15
* Built-in middleware engine for request/response transformation (validation coming soon).
16
16
* Works with micro function (one or a few routes) and monolithic functions (see [Considerations](#considerations)).
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:
| 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"} |
| Lambda Function URL |[Function URL configuration](https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html){target="_blank"} |
31
40
32
41
<!-- 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. -->
33
42
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.
35
44
36
45
??? "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"
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.
46
67
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.
48
69
49
70
#### Response auto-serialization
50
71
@@ -71,6 +92,9 @@ For your convenience, when you return a JavaScript object from your route handle
!!! 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
+
74
98
### Dynamic routes
75
99
76
100
You can use `/todos/:todoId` to configure dynamic URL paths, where `:todoId` will be resolved at runtime.
0 commit comments