-
Notifications
You must be signed in to change notification settings - Fork 180
Description
Expected Behavior
If you see the code snippet below, if you place the makeHandlerIdempotent call above the parser the middleware will fail if there is an error as when the middleware is going back up the chain on the other side the hash is different as httpJsonBodyParser has mutated the request.
So the expected behaviour is that makeHandlerIdempotent retains its own reference to the request when it receives it, so that when it creates the response other middleware do not affect it.
Current Behavior
If you use httpJsonBodyParser the makeHandlerIdempotent will not function if placed before the parser in the chain it will result in an error.
Code snippet
export const handle = middy(Sentry.wrapHandler(handler))
.use(errorHandlerMiddleware())
.use(httpHeaderNormalizer())
.use(httpJsonBodyParser())
.use(makeHandlerIdempotent({ persistenceStore, config: idempotencyConfig }))
.use(schemaValidatorMiddleware({ schema: RequestSchema }))
Steps to Reproduce
- Setup a lambda with
makeHandlerIdempotentbeforehttpJsonBodyParser - Call the lambda with the same request at the same time to trigger either a 409 or 500 from
makeHandlerIdempotent - Observe error as it can't find the entry in the table to remove as the hash differs
Possible Solution
The middleware retains a reference to the hash created for the request so it isn't reliant on the request when the response is created.
Powertools for AWS Lambda (TypeScript) version
latest
AWS Lambda function runtime
22.x
Packaging format used
npm
Execution logs
Metadata
Metadata
Assignees
Labels
Type
Projects
Status