Skip to content

Commit d89d170

Browse files
authored
Merge branch 'main' into chore/ci_input_sanitization
2 parents c700935 + 4daeaad commit d89d170

File tree

87 files changed

+1857
-1459
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1857
-1459
lines changed

.github/workflows/make-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ jobs:
5252
with:
5353
node-version: "22"
5454
cache: "npm"
55+
registry-url: 'https://registry.npmjs.org'
5556
- name: Setup auth tokens
5657
env:
5758
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

.github/workflows/publish-package.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
with:
4444
node-version: "22"
4545
cache: "npm"
46+
registry-url: 'https://registry.npmjs.org'
4647
- name: Setup auth tokens
4748
env:
4849
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,28 @@
11
# Change Log
22

3+
## [2.27.0](https://github.com/aws-powertools/powertools-lambda-typescript/compare/v2.26.1...v2.27.0) (2025-09-24)
4+
5+
### Bug Fixes
6+
7+
- **batch** fixed the build issue with Batch processor due to missing dependencies ([#4498](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4498)) ([ef67b43](https://github.com/aws-powertools/powertools-lambda-typescript/commit/ef67b43921f1d67b06b3257fb0f96c74e0d6dbae))
8+
- **event-handler** fixed CORS behaviour not aligned with CORS spec ([#4512](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4512)) ([dd368fa](https://github.com/aws-powertools/powertools-lambda-typescript/commit/dd368fa3eb08a86c2d5aad3cf9b832d7a8288486))
9+
- **event-handler** run global middleware on all requests for REST API ([#4507](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4507)) ([49d5f8a](https://github.com/aws-powertools/powertools-lambda-typescript/commit/49d5f8a4f36a5af26c573f7706347f34ec70689e))
10+
11+
### Improvements
12+
13+
- **event-handler** rename HttpErrorCodes to HttpStatusCodes ([#4543](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4543)) ([e53aa88](https://github.com/aws-powertools/powertools-lambda-typescript/commit/e53aa8816325f21510706e3f9e62fb0a76692915))
14+
- **event-handler** made error handler responses versatile ([#4536](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4536)) ([f08b366](https://github.com/aws-powertools/powertools-lambda-typescript/commit/f08b366b79152d338ebefb5a25caacade6846919))
15+
- **event-handler** changed path parameter in middleware and routehandler signature ([#4532](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4532)) ([278fca0](https://github.com/aws-powertools/powertools-lambda-typescript/commit/278fca0491ce9cb955326523557c3ddf9d03dbc5))
16+
- **event-handler** change the Middleware and RequestContext signatures ([#4530](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4530)) ([a05c074](https://github.com/aws-powertools/powertools-lambda-typescript/commit/a05c07411629d1e23a9cb3fec8a78cf23bd8dd0c))
17+
18+
### Features
19+
20+
- **event-handler** implemented route prefixes in HTTP event handler ([#4523](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4523)) ([8913854](https://github.com/aws-powertools/powertools-lambda-typescript/commit/89138542cd9e195555299f401646ae94d0bb50ee))
21+
- **event-handler** throw error when middleware does not await next() ([#4511](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4511)) ([b0b43e8](https://github.com/aws-powertools/powertools-lambda-typescript/commit/b0b43e862fb189941fe9db220580884e7707d541))
22+
- **event-handler** add CORS middleware support ([#4477](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4477)) ([972cd1f](https://github.com/aws-powertools/powertools-lambda-typescript/commit/972cd1f86b6ea01c93abef5e6cde7876360196f1))
23+
- **event-handler** added compress middleware for the REST API event handler ([#4495](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4495)) ([320e0dc](https://github.com/aws-powertools/powertools-lambda-typescript/commit/320e0dcaa07476de3b7d07209ef27379b9d4900a))
24+
25+
326
## [2.26.1](https://github.com/aws-powertools/powertools-lambda-typescript/compare/v2.26.0...v2.26.1) (2025-09-15)
427

528
### Bug Fixes

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
![GitHub Release](https://img.shields.io/github/v/release/aws-powertools/powertools-lambda-typescript?style=flat)
66
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=aws-powertools_powertools-lambda-typescript&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=aws-powertools_powertools-lambda-typescript)
77
[![Security Rating](https://sonarcloud.io/api/project_badges/measure?project=aws-powertools_powertools-lambda-typescript&metric=security_rating)](https://sonarcloud.io/summary/new_code?id=aws-powertools_powertools-lambda-typescript)
8-
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/aws-powertools/powertools-lambda-typescript/badge)](https://api.securityscorecards.dev/projects/github.com/aws-powertools/powertools-lambda-typescript)
8+
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/aws-powertools/powertools-lambda-typescript/badge)](https://scorecard.dev/viewer/?uri=github.com/aws-powertools/powertools-lambda-typescript)
9+
910
[![Discord](https://img.shields.io/badge/Discord-Join_Community-7289da.svg)](https://discord.gg/B8zZKbbyET)
1011

1112
Powertools for AWS Lambda (TypeScript) is a developer toolkit to implement Serverless [best practices and increase developer velocity](https://docs.powertools.aws.dev/lambda/typescript/latest/#features).

docs/features/event-handler/rest.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ Please [check this issue](https://github.com/aws-powertools/powertools-lambda-ty
128128

129129
### Accessing request details
130130

131-
You can access request details such as headers, query parameters, and body using the `Request` object provided to your route handlers and middleware functions via `reqCtx.request`.
131+
You can access request details such as headers, query parameters, and body using the `Request` object provided to your route handlers and middleware functions via `reqCtx.req`.
132132

133133
### Handling not found routes
134134

@@ -148,6 +148,8 @@ You can use the `errorHandler()` method as a higher-order function or class meth
148148

149149
This allows you to catch and return custom error responses, or perform any other error handling logic you need.
150150

151+
Error handlers receive the error object and the request context as arguments, and can return a [`Response` object](#returning-response-objects) or a JavaScript object that will be auto-serialized as per the [response auto-serialization](#response-auto-serialization) section.
152+
151153
!!! tip "You can also pass a list of error classes to the `errorHandler()` method."
152154

153155
=== "index.ts"
@@ -158,15 +160,17 @@ This allows you to catch and return custom error responses, or perform any other
158160

159161
### Throwing HTTP errors
160162

161-
You can throw HTTP errors in your route handlers to return specific HTTP status codes and messages. Event Handler provides a set of built-in HTTP error classes that you can use to throw common HTTP errors.
163+
You can throw HTTP errors in your route handlers to stop execution and return specific HTTP status codes and messages. Event Handler provides a set of built-in HTTP error classes that you can use to throw common HTTP errors.
162164

163165
This ensures that your Lambda function doesn't fail but returns a well-defined HTTP error response to the client.
164166

165167
If you need to send custom headers or a different response structure/code, you can use the [Response](#returning-response-objects) object instead.
166168

169+
!!! tip "You can throw HTTP errors in your route handlers, middleware, or custom error handlers!"
170+
167171
=== "index.ts"
168172

169-
```ts hl_lines="3 10"
173+
```ts hl_lines="3 11"
170174
--8<-- "examples/snippets/event-handler/rest/gettingStarted_throwing_http_errors.ts:3"
171175
```
172176

@@ -194,15 +198,21 @@ All error classes accept optional parameters for custom messages and additional
194198

195199
### Route prefixes
196200

197-
!!! note "Coming soon"
198-
199201
When defining multiple routes related to a specific resource, it's common to have a shared prefix. For example, you might have several routes that all start with `/todos`.
200202

201203
For example, if you have a custom domain `api.example.com` and you want to map it to the `/v1` base path of your API. In this case, all the requests will contain `/v1/<resource>` in the path, requiring you to repeat the `/v1` prefix in all your route definitions.
202204

203-
At the moment, you have to manually include the prefix in each route definition, however we are planning to add support for route prefixes in a future release.
205+
To avoid repeating the prefix in each route definition, you can use the `prefix` constructor parameter when creating a new `Router` instance, and we'll automatically strip it from the request path before matching routes. After mapping a path prefix, the new root path will automatically be mapped to the path argument of `/`.
206+
207+
=== "index.ts"
208+
209+
```ts hl_lines="4 7"
210+
--8<-- "examples/snippets/event-handler/rest/gettingStarted_route_prefix.ts:3"
211+
```
204212

205-
Please [check this issue](https://github.com/aws-powertools/powertools-lambda-typescript/issues/4513) for more details and examples, and add 👍 if you would like us to prioritize it.
213+
This is also useful when splitting routes into separate files (see [Split routers](#split-routers) section) or when using [API mappings](https://docs.aws.amazon.com/apigateway/latest/developerguide/rest-api-mappings.html){target="_blank"} to map custom domains to specific base paths.
214+
215+
For example, when using `prefix: '/pay'`, there is no difference between a request path of `/pay` and `/pay/`; and the path argument would be defined as `/`.
206216

207217
## Advanced
208218

@@ -213,9 +223,8 @@ incoming request and your route handler. They provide a way to implement cross-c
213223
concerns like authentication, logging, validation, and response transformation without
214224
cluttering your route handlers.
215225

216-
Each middleware function receives the following arguments:
226+
Each middleware function receives two arguments:
217227

218-
* **params** - Route parameters extracted from the URL path
219228
* **reqCtx** - Request context containing the event, Lambda context, request, and response objects
220229
* **next** - A function to pass control to the next middleware in the chain
221230

@@ -312,6 +321,11 @@ that no post-processing of your request will occur.
312321
A common pattern to create reusable middleware is to implement a factory functions that
313322
accepts configuration options and returns a middleware function.
314323

324+
!!! note "Always `await next()` unless returning early"
325+
Middleware functions must always call `await next()` to pass control to the next middleware
326+
in the chain, unless you are intentionally returning early by returning a `Response` or
327+
JSON object.
328+
315329
=== "index.ts"
316330

317331
```ts hl_lines="20-21 36 41"

0 commit comments

Comments
 (0)