Skip to content

Commit 5a4571e

Browse files
committed
docs(idempotency): add callout about undefined early return
1 parent 1bd4725 commit 5a4571e

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Diff for: docs/utilities/idempotency.md

+2
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ Similar to the `makeIdempotent` function wrapper, you can quickly make your Lamb
206206
--8<-- "examples/snippets/idempotency/types.ts:3:16"
207207
```
208208

209+
Note that for the middleware to work, your Lambda function handler must return a value different from `undefined`. This is a [known limitation of Middy.js early return feature](https://github.com/middyjs/middy/issues/1236). If your use case requires early returns, you can use the `makeIdempotent` function wrapper instead.
210+
209211
### Choosing a payload subset for idempotency
210212

211213
Use [`IdempotencyConfig`](#customizing-the-default-behavior) to instruct the idempotent decorator to only use a portion of your payload to verify whether a request is idempotent, and therefore it should not be retried. When dealing with a more elaborate payload, where parts of the payload always change, you should use the **`eventKeyJmesPath`** parameter.

Diff for: packages/idempotency/src/middleware/makeHandlerIdempotent.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
import { IdempotencyHandler } from '../IdempotencyHandler.js';
2-
import { IdempotencyConfig } from '../IdempotencyConfig.js';
31
import {
4-
cleanupMiddlewares,
52
IDEMPOTENCY_KEY,
3+
cleanupMiddlewares,
64
} from '@aws-lambda-powertools/commons';
75
import type {
8-
AnyFunction,
9-
IdempotencyLambdaHandlerOptions,
10-
} from '../types/IdempotencyOptions.js';
11-
import type {
6+
JSONValue,
127
MiddlewareLikeObj,
138
MiddyLikeRequest,
14-
JSONValue,
159
} from '@aws-lambda-powertools/commons/types';
10+
import { IdempotencyConfig } from '../IdempotencyConfig.js';
11+
import { IdempotencyHandler } from '../IdempotencyHandler.js';
12+
import type {
13+
AnyFunction,
14+
IdempotencyLambdaHandlerOptions,
15+
} from '../types/IdempotencyOptions.js';
1616

1717
/**
1818
* @internal
@@ -90,6 +90,11 @@ const shouldSkipIdempotency = (request: MiddyLikeRequest): boolean => {
9090
* ).use(makeHandlerIdempotent({ persistenceStore: dynamoDBPersistenceLayer }));
9191
* ```
9292
*
93+
* Note that for the middleware to work, your Lambda function handler must return a value different from `undefined`.
94+
* This is a [known limitation of Middy.js early return feature](https://github.com/middyjs/middy/issues/1236).
95+
*
96+
* If your use case requires early returns, you can use the {@link index.makeIdempotent | makeIdempotent()} function wrapper instead.
97+
*
9398
* @param options - Options for the idempotency middleware
9499
*/
95100
const makeHandlerIdempotent = (

0 commit comments

Comments
 (0)