Skip to content

Commit 004894a

Browse files
authored
docs(idempotency): fix docs (#1724)
* add decorator and tests * remove unused code, merged comments * add idempotecy decorator to docs * add idempotency decorator tests * address comments from review * remove whitespace
1 parent d138673 commit 004894a

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

Diff for: docs/snippets/idempotency/idempotentDecoratorBase.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import type { Context } from 'aws-lambda';
2-
import { LambdaInterface } from '@aws-lambda-powertools/commons';
2+
import type { LambdaInterface } from '@aws-lambda-powertools/commons';
33
import {
44
IdempotencyConfig,
55
idempotent,
66
} from '@aws-lambda-powertools/idempotency';
77
import { DynamoDBPersistenceLayer } from '@aws-lambda-powertools/idempotency/dynamodb';
8-
import { Request, Response } from './types';
8+
import type { Request, Response } from './types';
99

1010
const dynamoDBPersistenceLayer = new DynamoDBPersistenceLayer({
1111
tableName: 'idempotencyTableName',

Diff for: docs/utilities/idempotency.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ After processing this request successfully, a second request containing the exac
139139
See [Choosing a payload subset for idempotency](#choosing-a-payload-subset-for-idempotency) for more elaborate use cases.
140140

141141

142-
You can also use the `makeIdempotent` function wrapper 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.
142+
You can also use the `makeIdempotent` function wrapper on any method 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.
143143

144144
???+ warning "Limitation"
145145
Make sure to return a JSON serializable response from your function, otherwise you'll get an error.
@@ -173,6 +173,9 @@ You can also use the `@idempotent` decorator to make your Lambda handler idempot
173173
=== "types.ts"
174174

175175
```typescript
176+
--8<-- "docs/snippets/idempotency/types.ts"
177+
```
178+
176179

177180
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.
178181
The configuration options for the `@idempotent` decorator are the same as the ones for the `makeIdempotent` function wrapper.

Diff for: packages/idempotency/README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ You can use the package in both TypeScript and JavaScript code bases.
2525
## Intro
2626

2727
This package provides a utility to implement idempotency in your Lambda functions.
28-
You can either use it to wrap a function, decorate a function, or as Middy middleware to make your AWS Lambda handler idempotent.
28+
You can either use it to wrap a function, decorate a method, or as Middy middleware to make your AWS Lambda handler idempotent.
2929

3030
The current implementation provides a persistence layer for Amazon DynamoDB, which offers a variety of configuration options. You can also bring your own persistence layer by extending the `BasePersistenceLayer` class.
3131

@@ -181,8 +181,8 @@ const persistenceStore = new DynamoDBPersistenceLayer({
181181
class MyHandler extends LambdaInterface {
182182
@idempotent({ persistenceStore: dynamoDBPersistenceLayer })
183183
public async handler(
184-
event: APIGatewayProxyEvent,
185-
context: Context
184+
event: APIGatewayProxyEvent,
185+
context: Context
186186
): Promise<void> {
187187
// your code goes here here
188188
}
@@ -192,7 +192,7 @@ const handlerClass = new MyHandler();
192192
export const handler = handlerClass.handler.bind(handlerClass);
193193
```
194194

195-
Using the same decorator, you can also make any other arbitrary function idempotent.
195+
Using the same decorator, you can also make any other arbitrary method idempotent.
196196

197197
```ts
198198
import { idempotent } from '@aws-lambda-powertools/idempotency';
@@ -207,18 +207,18 @@ const persistenceStore = new DynamoDBPersistenceLayer({
207207
class MyHandler extends LambdaInterface {
208208

209209
public async handler(
210-
event: unknown,
211-
context: Context
210+
event: unknown,
211+
context: Context
212212
): Promise<void> {
213213
for(const record of event.Records) {
214214
await this.processIdempotently(record);
215215
}
216216
}
217217

218-
@idempotent({ persistenceStore: dynamoDBPersistenceLayer })
219-
private async process(record: unknown): Promise<void> {
220-
// process each code idempotently
221-
}
218+
@idempotent({ persistenceStore: dynamoDBPersistenceLayer })
219+
private async process(record: unknown): Promise<void> {
220+
// process each code idempotently
221+
}
222222
}
223223

224224
const handlerClass = new MyHandler();

Diff for: packages/idempotency/src/idempotencyDecorator.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@ import { makeIdempotent } from './makeIdempotent';
1111
* import {
1212
* DynamoDBPersistenceLayer,
1313
* idempotentLambdaHandler
14-
* } from '@aws-lambda-powertools/idempotency'
14+
* } from '@aws-lambda-powertools/idempotency';
15+
* import type { LambdaInterface } from '@aws-lambda-powertools/commons';
1516
*
16-
* class MyLambdaFunction {
17+
* class MyLambdaFunction implements LambdaInterface{
1718
* @idempotent({ persistenceStore: new DynamoDBPersistenceLayer() })
1819
* async handler(event: any, context: any) {
1920
* return "Hello World";
@@ -29,9 +30,10 @@ import { makeIdempotent } from './makeIdempotent';
2930
* import {
3031
* DynamoDBPersistenceLayer,
3132
* idempotentFunction
32-
* } from '@aws-lambda-powertools/idempotency'
33+
* } from '@aws-lambda-powertools/idempotency';
34+
* import type { LambdaInterface } from '@aws-lambda-powertools/commons';
3335
*
34-
* class MyClass {
36+
* class MyClass implements LambdaInterface {
3537
*
3638
* public async handler(_event: any, _context: any) {
3739
* for(const record of _event.records){

0 commit comments

Comments
 (0)