From 5a4571ed4ab4c1c3812ab960f22a16a25da5c69e Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 12 Sep 2024 18:47:54 +0200 Subject: [PATCH 1/3] docs(idempotency): add callout about undefined early return --- docs/utilities/idempotency.md | 2 ++ .../src/middleware/makeHandlerIdempotent.ts | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/docs/utilities/idempotency.md b/docs/utilities/idempotency.md index 552fb4bcec..aa85c3ad7a 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" ``` +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. + ### 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..3869e1e9d9 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 })); * ``` * + * 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 {@link index.makeIdempotent | makeIdempotent()} function wrapper instead. + * * @param options - Options for the idempotency middleware */ const makeHandlerIdempotent = ( From 3496aeec08dbf3c4152d401b31baf27148c76488 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 12 Sep 2024 19:49:12 +0200 Subject: [PATCH 2/3] Update docs/utilities/idempotency.md Co-authored-by: Leandro Damascena --- docs/utilities/idempotency.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/utilities/idempotency.md b/docs/utilities/idempotency.md index aa85c3ad7a..1c6395db29 100644 --- a/docs/utilities/idempotency.md +++ b/docs/utilities/idempotency.md @@ -206,7 +206,7 @@ Similar to the `makeIdempotent` function wrapper, you can quickly make your Lamb --8<-- "examples/snippets/idempotency/types.ts:3:16" ``` -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. +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 From 28bfd12dee5852a2de804cb65c1a5f0a9bccfa63 Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Thu, 12 Sep 2024 19:49:32 +0200 Subject: [PATCH 3/3] chore: accept suggestion --- packages/idempotency/src/middleware/makeHandlerIdempotent.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/idempotency/src/middleware/makeHandlerIdempotent.ts b/packages/idempotency/src/middleware/makeHandlerIdempotent.ts index 3869e1e9d9..3e05ef7045 100644 --- a/packages/idempotency/src/middleware/makeHandlerIdempotent.ts +++ b/packages/idempotency/src/middleware/makeHandlerIdempotent.ts @@ -90,8 +90,8 @@ const shouldSkipIdempotency = (request: MiddyLikeRequest): boolean => { * ).use(makeHandlerIdempotent({ persistenceStore: dynamoDBPersistenceLayer })); * ``` * - * 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). + * 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. *