Skip to content

Bug: Usage with middy httpJsonBodyParser #3424

@andrewdavidcostello

Description

@andrewdavidcostello

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

  1. Setup a lambda with makeHandlerIdempotent before httpJsonBodyParser
  2. Call the lambda with the same request at the same time to trigger either a 409 or 500 from makeHandlerIdempotent
  3. 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

No one assigned

    Labels

    bugSomething isn't workingidempotencyThis item relates to the Idempotency UtilityrejectedThis is something we will not be working on. At least, not in the measurable future

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions