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/idempotency.md
-14
Original file line number
Diff line number
Diff line change
@@ -162,13 +162,6 @@ The function this example has two arguments, note that while wrapping it with th
162
162
163
163
You can also use the `@idempotent` decorator to make your Lambda handler idempotent, similar to the `makeIdempotent` function wrapper.
164
164
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
-
172
165
=== "index.ts"
173
166
174
167
```typescript hl_lines="17"
@@ -181,15 +174,8 @@ You can also use the `@idempotent` decorator to make your Lambda handler idempot
181
174
--8<-- "examples/snippets/idempotency/types.ts"
182
175
```
183
176
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
-
187
177
### MakeHandlerIdempotent Middy middleware
188
178
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
-
193
179
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.
194
180
195
181
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.
Copy file name to clipboardExpand all lines: docs/features/logger.md
-11
Original file line number
Diff line number
Diff line change
@@ -115,23 +115,12 @@ This functionality will include the following keys in your structured logs:
115
115
116
116
=== "Middy Middleware"
117
117
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
-
122
118
```typescript hl_lines="2 14"
123
119
--8<-- "examples/snippets/logger/middy.ts"
124
120
```
125
121
126
122
=== "Decorator"
127
123
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.
Copy file name to clipboardExpand all lines: docs/features/metrics.md
-11
Original file line number
Diff line number
Diff line change
@@ -201,10 +201,6 @@ You can add default dimensions to your metrics by passing them as parameters in
201
201
202
202
=== "Middy middleware"
203
203
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"}.
@@ -217,13 +213,6 @@ You can add default dimensions to your metrics by passing them as parameters in
217
213
218
214
=== "with logMetrics decorator"
219
215
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.
Copy file name to clipboardExpand all lines: docs/features/tracer.md
+1-10
Original file line number
Diff line number
Diff line change
@@ -153,21 +153,12 @@ You can quickly start by importing the `Tracer` class, initialize it outside the
153
153
154
154
=== "Middy Middleware"
155
155
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
-
160
156
```typescript hl_lines="2 15 17"
161
157
--8<-- "examples/snippets/tracer/middy.ts"
162
158
```
163
159
164
160
=== "Decorator"
165
161
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
-
171
162
```typescript hl_lines="8"
172
163
--8<-- "examples/snippets/tracer/decorator.ts"
173
164
```
@@ -185,7 +176,7 @@ When using the `captureLambdaHandler` decorator or middleware, Tracer performs t
185
176
* Handles the lifecycle of the subsegment
186
177
* Creates a `ColdStart` annotation to easily filter traces that have had an initialization overhead
187
178
* 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
Copy file name to clipboardExpand all lines: docs/features/validation.md
-5
Original file line number
Diff line number
Diff line change
@@ -34,11 +34,6 @@ The `@validator` decorator is a class method decorator that you can use to valid
34
34
35
35
If the validation fails, we will throw a `SchemaValidationError`.
36
36
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.
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.
141
165
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.
Copy file name to clipboardExpand all lines: docs/getting-started/typescript-settings.md
+4-6
Original file line number
Diff line number
Diff line change
@@ -1,21 +1,19 @@
1
1
---
2
2
title: Typescript Settings
3
-
description: Configuration settings for using Powertools with TypeScript
3
+
description: Configuration settings for using with TypeScript
4
4
---
5
5
6
6
<!-- markdownlint-disable MD043 -->
7
7
8
8
While you can use the toolkit with JavaScript, using TypeScript is recommended.
9
9
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.
13
11
14
12
## TypeScript Configuration
15
13
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.
17
15
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.
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.
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.
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.
0 commit comments