-
Notifications
You must be signed in to change notification settings - Fork 146
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
Feature request: idempotency Middy middleware #1293
Comments
As a result of the discussion in #1410 I have been thinking about how to implement this and realized that there's an added challenge related to how Middy works. Middy allows middleware authors to return early in the This mean that if the idempotency middleware is preceded or followed by other Powertools middleware they won't be able to perform any post-request action. This is problematic especially for the This is not a case that is limited to the middleware being discussed in this issue and it also affects any custom middleware implemented by Powertools users so we will need to document and/or expose a way for middleware that do an early return to cleanup after themselves before returning. I'm still unsure on the best way to handle this, but whatever solution we settle on will have to be adopted by this middleware, hence this note. I'll link back to this issue once we have more info. |
|
This is now released under v1.9.0 version! |
Use Case
Users who already use Middy middleware in their functions should be able to make their function
handler
idempotent via amakeHandlerIdempotent
Middy-compatible middleware.Solution/User Experience
The
makeHandlerIdempotent
middleware should work with bothsync
andasync
functionhandler
s. The middleware should accept an object with mandatorypersistenceStore
and an optionalconfig
one. The former should be an instance of any class that extendsBasePersistenceLayer
, while the latter should be an instance of the classIdempotencyConfig
.Following the Powertools for Python decorator implementation, the middleware should:
POWERTOOLS_IDEMPOTENCY_DISABLED
env variable has a truthy value (usingEnvironmentVariableService
) -onBefore
onBefore
onBefore
IdempotencyHandler
-onBefore
IdempotencyHandler.handle()
method -onBefore
This last step will ensure that the
IdempotencyHandler
will perform all the actions needed to make the function idempotent.Given how Middy handles requests and errors, there's a chance that the current public methods of
IdempotencyHandler
might not be enough and we'd need to add additional public methods to call in theonAfter
oronError
phase.Alternative solutions
No response
Acknowledgment
The text was updated successfully, but these errors were encountered: