Skip to content

Commit f025735

Browse files
committed
chore: address feedback
1 parent b670230 commit f025735

14 files changed

+152
-166
lines changed

docs/features/idempotency.md

-14
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,6 @@ The function this example has two arguments, note that while wrapping it with th
162162

163163
You can also use the `@idempotent` decorator to make your Lambda handler idempotent, similar to the `makeIdempotent` function wrapper.
164164

165-
!!! info
166-
The class method decorators in this project follow the experimental implementation enabled via the [`experimentalDecorators` compiler option](https://www.typescriptlang.org/tsconfig#experimentalDecorators) in TypeScript.
167-
168-
Additionally, they are implemented to decorate async methods. When decorating a synchronous one, the decorator replaces its implementation with an async one causing the caller to have to `await` the now decorated method.
169-
170-
If this is not the desired behavior, you can use one of the other patterns to make your logic idempotent.
171-
172165
=== "index.ts"
173166

174167
```typescript hl_lines="17"
@@ -181,15 +174,8 @@ You can also use the `@idempotent` decorator to make your Lambda handler idempot
181174
--8<-- "examples/snippets/idempotency/types.ts"
182175
```
183176

184-
You can use the decorator on your Lambda handler or on any function that returns a response to make it idempotent. This is useful when you want to make a specific logic idempotent, for example when your Lambda handler performs multiple side effects and you only want to make a specific one idempotent.
185-
The configuration options for the `@idempotent` decorator are the same as the ones for the `makeIdempotent` function wrapper.
186-
187177
### MakeHandlerIdempotent Middy middleware
188178

189-
!!! tip "A note about Middy"
190-
We guarantee support for Middy.js `v4.x` through `v6.x` versions.
191-
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.
192-
193179
If you are using [Middy.js](https://middy.js.org){target="_blank"} as your middleware engine, you can use the `makeHandlerIdempotent` middleware to make your Lambda handler idempotent.
194180

195181
Similar to the `makeIdempotent` function wrapper, you can quickly make your Lambda handler idempotent by initializing the `DynamoDBPersistenceLayer` class and using it with the `makeHandlerIdempotent` middleware.

docs/features/logger.md

-11
Original file line numberDiff line numberDiff line change
@@ -115,23 +115,12 @@ This functionality will include the following keys in your structured logs:
115115

116116
=== "Middy Middleware"
117117

118-
!!! tip "A note about Middy"
119-
We guarantee support for Middy.js `v4.x` through `v6.x` versions.
120-
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.
121-
122118
```typescript hl_lines="2 14"
123119
--8<-- "examples/snippets/logger/middy.ts"
124120
```
125121

126122
=== "Decorator"
127123

128-
!!! note
129-
The class method decorators in this project follow the experimental implementation enabled via the [`experimentalDecorators` compiler option](https://www.typescriptlang.org/tsconfig#experimentalDecorators) in TypeScript.
130-
131-
Additionally, they are implemented to decorate async methods. When decorating a synchronous one, the decorator replaces its implementation with an async one causing the caller to have to `await` the now decorated method.
132-
133-
If this is not the desired behavior, you can call the `logger.injectLambdaContext()` method directly in your handler.
134-
135124
```typescript hl_lines="8"
136125
--8<-- "examples/snippets/logger/decorator.ts"
137126
```

docs/features/metrics.md

-11
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ You can add default dimensions to your metrics by passing them as parameters in
201201

202202
=== "Middy middleware"
203203

204-
!!! tip "A note about Middy"
205-
We guarantee support for Middy.js `v4.x` through `v6.x` versions.
206-
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.
207-
208204
```typescript hl_lines="24-26"
209205
--8<-- "examples/snippets/metrics/defaultDimensionsMiddy.ts"
210206
```
@@ -217,13 +213,6 @@ You can add default dimensions to your metrics by passing them as parameters in
217213

218214
=== "with logMetrics decorator"
219215

220-
!!! note
221-
The class method decorators in this project follow the experimental implementation enabled via the [`experimentalDecorators` compiler option](https://www.typescriptlang.org/tsconfig#experimentalDecorators) in TypeScript.
222-
223-
Additionally, they are implemented to decorate async methods. When decorating a synchronous one, the decorator replaces its implementation with an async one causing the caller to have to `await` the now decorated method.
224-
225-
If this is not the desired behavior, you can use the `logMetrics` middleware instead.
226-
227216
```typescript hl_lines="12"
228217
--8<-- "examples/snippets/metrics/defaultDimensionsDecorator.ts"
229218
```

docs/features/tracer.md

+1-10
Original file line numberDiff line numberDiff line change
@@ -153,21 +153,12 @@ You can quickly start by importing the `Tracer` class, initialize it outside the
153153

154154
=== "Middy Middleware"
155155

156-
!!! tip "A note about Middy"
157-
We guarantee support for Middy.js `v4.x` through `v6.x` versions.
158-
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.
159-
160156
```typescript hl_lines="2 15 17"
161157
--8<-- "examples/snippets/tracer/middy.ts"
162158
```
163159

164160
=== "Decorator"
165161

166-
!!! note
167-
The class method decorators in this project follow the experimental implementation enabled via the [`experimentalDecorators` compiler option](https://www.typescriptlang.org/tsconfig#experimentalDecorators) in TypeScript.
168-
169-
Additionally, they are implemented to decorate async methods. When decorating a synchronous one, the decorator replaces its implementation with an async one causing the caller to have to `await` the now decorated method.
170-
171162
```typescript hl_lines="8"
172163
--8<-- "examples/snippets/tracer/decorator.ts"
173164
```
@@ -185,7 +176,7 @@ When using the `captureLambdaHandler` decorator or middleware, Tracer performs t
185176
* Handles the lifecycle of the subsegment
186177
* Creates a `ColdStart` annotation to easily filter traces that have had an initialization overhead
187178
* Creates a `Service` annotation to easily filter traces that have a specific service name
188-
* Captures any response, or full exceptions generated by the handler, and include them as tracing metadata
179+
* Captures any response, or full exceptions generated by the handler, and includes them as tracing metadata
189180

190181
### Annotations & Metadata
191182

docs/features/validation.md

-5
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,6 @@ The `@validator` decorator is a class method decorator that you can use to valid
3434

3535
If the validation fails, we will throw a `SchemaValidationError`.
3636

37-
??? note "A note on class method decorators"
38-
The class method decorators in this project follow the experimental implementation enabled via the [`experimentalDecorators` compiler option](https://www.typescriptlang.org/tsconfig#experimentalDecorators) in TypeScript. We will add support for the newer Stage 3 decorators proposal in the next major release.
39-
40-
All our decorators assume that the method they are decorating is an async method. This means that even when decorating a synchronous method, it will return a promise. If this is not the desired behavior, you can use one of the other patterns to validate your payloads.
41-
4237
=== "gettingStartedDecorator.ts"
4338

4439
```typescript hl_lines="1 11-14"

docs/getting-started/lambda-layers.md

+29-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ You can add our layer both in the [AWS Lambda Console _(under `Layers`)_](https:
1111

1212
### Layer ARNs
1313

14-
We publish the Lambda Layer for Powertools for AWS Lambda (TypeScript) in all commercial regions and AWS GovCloud (US) regions.
14+
We publish the Lambda Layer for Powertools for AWS Lambda in all commercial regions and AWS GovCloud (US) regions.
1515

1616
???+ tip "Spotted a missing region?"
1717

@@ -89,6 +89,30 @@ Change `{aws::region}` to your AWS region, e.g. `eu-west-1`, and run the followi
8989

9090
```bash title="AWS CLI command to download Lambda Layer content"
9191
aws lambda get-layer-version-by-arn --arn arn:aws:lambda:{aws::region}:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:24 --region {aws::region}
92+
93+
# output
94+
{
95+
"Content": {,
96+
"Location": "https://awslambda-eu-west-1-layers.s3.eu-west-1.amazonaws.com/...",
97+
"CodeSha256": "gwGIE8w0JckdDeDCTX6FbWObb2uIDwgiaAq78gMWDyA=",
98+
"CodeSize": 3548324
99+
},
100+
"LayerArn": "arn:aws:lambda:eu-west-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2",
101+
"LayerVersionArn": "arn:aws:lambda:eu-west-1:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:24",
102+
"Description": "Powertools for AWS Lambda (TypeScript) version 2.18.0",
103+
"CreatedDate": "2025-04-08T07:38:30.424+0000",
104+
"Version": 24,
105+
"CompatibleRuntimes": [
106+
"nodejs18.x",
107+
"nodejs20.x",
108+
"nodejs22.x"
109+
],
110+
"LicenseInfo": "MIT-0",
111+
"CompatibleArchitectures": [
112+
"arm64",
113+
"x86_64"
114+
]
115+
}
92116
```
93117

94118
### How to use with Infrastructure as Code
@@ -112,7 +136,7 @@ aws lambda get-layer-version-by-arn --arn arn:aws:lambda:{aws::region}:094274105
112136
`arn:aws:lambda:${Stack.of(this).region}:094274105915:layer:AWSLambdaPowertoolsTypeScriptV2:24`
113137
);
114138
115-
new Function(this, 'Function', {
139+
new NodejsFunction(this, 'Function', {
116140
runtime: Runtime.NODEJS_22_X,
117141
// Add the Layer to a Lambda function
118142
layers: [powertoolsLayer],
@@ -137,9 +161,9 @@ aws lambda get-layer-version-by-arn --arn arn:aws:lambda:{aws::region}:094274105
137161
});
138162
```
139163

140-
Check the [documentation](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_nodejs.BundlingOptions.html#externalmodules) for more details.
164+
Check the AWS CDK `NodeJsFunction` [documentation](https://docs.aws.amazon.com/cdk/api/v2/docs/aws-cdk-lib.aws_lambda_nodejs.BundlingOptions.html#externalmodules) for more details.
141165

142-
You can also use AWS SSM Parameter Store to dynamically add Powertools for AWS Lambda and resolve the Layer ARN from SSM Parameter Store in your code, allowing you to pin to `latest` or a specific Powertools for AWS Lambda version.
166+
You can also use AWS SSM Parameter Store to dynamically resolve the Layer ARN from SSM Parameter Store and add the toolkit in your code, allowing you to pin to `latest` or a specific Powertools for AWS version.
143167

144168
```typescript hl_lines="5 15-17"
145169
import { Stack } from 'aws-cdk-lib';
@@ -161,7 +185,7 @@ aws lambda get-layer-version-by-arn --arn arn:aws:lambda:{aws::region}:094274105
161185
})
162186
);
163187
164-
new Function(this, 'Function', {
188+
new NodejsFunction(this, 'Function', {
165189
runtime: Runtime.NODEJS_22_X,
166190
// Add the Layer to a Lambda function
167191
layers: [powertoolsLayer],

docs/getting-started/navigating-the-toolkit.md

-103
This file was deleted.

docs/getting-started/typescript-settings.md

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
---
22
title: Typescript Settings
3-
description: Configuration settings for using Powertools with TypeScript
3+
description: Configuration settings for using with TypeScript
44
---
55

66
<!-- markdownlint-disable MD043 -->
77

88
While you can use the toolkit with JavaScript, using TypeScript is recommended.
99

10-
The toolkit is written in TypeScript, and the type definitions are included in the package. This means you can take advantage of TypeScript's static typing and other features when using it.
11-
12-
We officially support TypeScript 5.0 and later, and our development is done using the latest version of TypeScript. We recommend using the latest version of TypeScript to take advantage of the latest features and improvements.
10+
The toolkit is written in TypeScript with bundled type definitions. We officially support TypeScript 5.0+ and recommend using the latest version to benefit from all features and improvements.
1311

1412
## TypeScript Configuration
1513

16-
The toolkit should work with most TypeScript configurations. The only requirement is that `experimentalDecorators` is set to `true` if you are using class method decorators. This is because we only support the legacy decorator proposal for now. We will support the new decorator proposal in the next major version of Powertools for AWS Lambda (TypeScript).
14+
If you use class method decorators, you must set `experimentalDecorators: true` in your tsconfig.json. This is because we currently support only the legacy decorator syntax. Support for the new decorator syntax will come in our next major release.
1715

18-
If you are looking for a starting point, the following `tsconfig.json` file is a good place to start. It includes the recommended settings along with some modern TypeScript features.
16+
The following `tsconfig.json` file is a good place to start and includes the recommended settings along with some modern TypeScript features.
1917

2018
```json
2119
{
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
title: Usage patterns
3+
description: Getting to know the Powertools for AWS Lambda toolkit
4+
---
5+
6+
<!-- markdownlint-disable MD043 -->
7+
8+
Powertools for AWS Lambda (TypeScript) is a collection of utilities designed to help you build serverless applications on AWS.
9+
10+
The toolkit is modular, so you can pick and choose the utilities you need for your application, but also combine them for a complete solution for your serverless applications.
11+
12+
## Patterns
13+
14+
Many of the utilities provided can be used with different patterns, depending on your preferences and the structure of your code.
15+
16+
### Class Method Decorator
17+
18+
If you prefer writing your business logic using Object-Oriented Programming (OOP) and TypeScript Classes, the Class Method decorator pattern is a good fit. This approach lets you decorate class methods with Powertools utilities, applying their functionality with minimal code changes.
19+
20+
This pattern works well when you want to integrate Powertools for AWS into an existing codebase without significant refactoring and with no additional runtime dependencies.
21+
22+
!!! note
23+
This approach relies on TypeScript's experimental decorator feature, see [TypeScript Settings](./typescript-settings.md) for more information.
24+
25+
```ts
26+
---8<-- "examples/snippets/getting-started/patterns-decorator.ts"
27+
```
28+
29+
All our decorators assume that the method they are decorating is asynchronous. This means that even when decorating a synchronous method, they will return a promise. If this is not the desired behavior, you can use one of the other patterns.
30+
31+
### Middy.js Middleware
32+
33+
If your existing codebase relies on the [Middy.js](https://middy.js.org/docs/) middleware engine, you can use the Powertools for AWS Lambda (TypeScript) middleware to integrate with your existing code. This approach is similar to the Class Method decorator pattern but uses the Middy.js middleware engine to apply Powertools utilities.
34+
35+
!!! note
36+
We guarantee support for Middy.js `v4.x` through `v6.x` versions.
37+
Check Middy.js docs to learn more about [best practices](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"} when working with Powertools for AWS middlewares.
38+
39+
```ts
40+
---8<-- "examples/snippets/getting-started/patterns-middyjs.ts"
41+
```
42+
43+
### Functional Approach
44+
45+
If you prefer a more functional programming style, you can use the Powertools for AWS Lambda (TypeScript) utilities directly in your code without decorators or middleware. This approach is more verbose but provides the most control over how the utilities are applied.
46+
47+
```ts
48+
---8<-- "examples/snippets/getting-started/patterns-functional.ts"
49+
```

docs/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ You can use Powertools for AWS Lambda in both TypeScript and JavaScript code bas
1818

1919
Adopt one, a few, or all industry practices. **Progressively**.
2020

21+
[:octicons-arrow-right-24: All features](./features/index.md)
22+
2123
- :heart:{ .lg .middle } __Support this project__
2224

2325
---

0 commit comments

Comments
 (0)