diff --git a/docs/utilities/idempotency.md b/docs/utilities/idempotency.md index 552fb4bcec..1c6395db29 100644 --- a/docs/utilities/idempotency.md +++ b/docs/utilities/idempotency.md @@ -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. diff --git a/packages/idempotency/src/middleware/makeHandlerIdempotent.ts b/packages/idempotency/src/middleware/makeHandlerIdempotent.ts index 3ce92a73a2..3e05ef7045 100644 --- a/packages/idempotency/src/middleware/makeHandlerIdempotent.ts +++ b/packages/idempotency/src/middleware/makeHandlerIdempotent.ts @@ -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 @@ -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 = (