Skip to content

docs(idempotency): add callout about undefined early return #3055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/utilities/idempotency.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ Similar to the `makeIdempotent` function wrapper, you can quickly make your Lamb
--8<-- "examples/snippets/idempotency/types.ts:3:16"
```

For the middleware to work, your Lambda function handler must return a value different from `undefined`. This is a [known limitation of the early return feature in Middy.js](https://github.com/middyjs/middy/issues/1236). If your use case requires early returns, you can use the `makeIdempotent` function wrapper instead.

### Choosing a payload subset for idempotency

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.
Expand Down
21 changes: 13 additions & 8 deletions packages/idempotency/src/middleware/makeHandlerIdempotent.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { IdempotencyHandler } from '../IdempotencyHandler.js';
import { IdempotencyConfig } from '../IdempotencyConfig.js';
import {
cleanupMiddlewares,
IDEMPOTENCY_KEY,
cleanupMiddlewares,
} from '@aws-lambda-powertools/commons';
import type {
AnyFunction,
IdempotencyLambdaHandlerOptions,
} from '../types/IdempotencyOptions.js';
import type {
JSONValue,
MiddlewareLikeObj,
MiddyLikeRequest,
JSONValue,
} from '@aws-lambda-powertools/commons/types';
import { IdempotencyConfig } from '../IdempotencyConfig.js';
import { IdempotencyHandler } from '../IdempotencyHandler.js';
import type {
AnyFunction,
IdempotencyLambdaHandlerOptions,
} from '../types/IdempotencyOptions.js';

/**
* @internal
Expand Down Expand Up @@ -90,6 +90,11 @@ const shouldSkipIdempotency = (request: MiddyLikeRequest): boolean => {
* ).use(makeHandlerIdempotent({ persistenceStore: dynamoDBPersistenceLayer }));
* ```
*
* For the middleware to work, your Lambda function handler must return a value different from `undefined`.
* This is a [known limitation of the early return feature in Middy.js](https://github.com/middyjs/middy/issues/1236).
*
* If your use case requires early returns, you can use the {@link index.makeIdempotent | makeIdempotent()} function wrapper instead.
*
* @param options - Options for the idempotency middleware
*/
const makeHandlerIdempotent = (
Expand Down