Can DynamoDB TTL behavior "break" @aws-lambda-powertools/idempotency? #1732
-
I have a concern about DynamoDB's TTL affecting the behavior of the powertool's idempotency package. The scenarioAccording to dynamodb's TTL documentation an entry can still remain in the DB and occur in queries although it has already been expired:
The ConcernThat raises the question whether the idempotency package might retrieve an already expired dynamoDB entry and returns the safed response instead of invoking the original function instead? Or takes the package care of that TTL behavior already? I appreciate any hint on this :) Thx |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi @HaaLeo, thank you for opening a question in our repository! Even though it's true that DynamoDB doesn't necessarily evict items as soon as their TTL has expired, Powertools is able to handle this case and their presence in the table does not prevent the Idempotency utility to detect that the operation should be in fact processed. When processing a new payload the Idempotency utility performs an optimistic write and tries to save the record as "in progress". The write operation uses a condition expression that includes the following statements (source):
If any of these conditions (concatenated by The request flow for this specific case is described in this section of the docs: https://docs.powertools.aws.dev/lambda/typescript/latest/utilities/idempotency/#expired-idempotency-records |
Beta Was this translation helpful? Give feedback.
Hi @HaaLeo, thank you for opening a question in our repository!
Even though it's true that DynamoDB doesn't necessarily evict items as soon as their TTL has expired, Powertools is able to handle this case and their presence in the table does not prevent the Idempotency utility to detect that the operation should be in fact processed.
When processing a new payload the Idempotency utility performs an optimistic write and tries to save the record as "in progress". The write operation uses a condition expression that includes the following statements (source):