Expected Behaviour
When enabling JMESPath payload validation in the Idempotency utility (https://docs.aws.amazon.com/powertools/java/latest/utilities/idempotency/#payload-validation) I expect that an IdempotencyValidationException is thrown when the expected field does not match the value of the cached field for this idempotency key.
Current Behaviour
This exception is not thrown in all cases anymore after introducing an optimization to save DynamoDB calls in PR #1821.
We are optimistically calling the putRecord operation and if this fails because the key already exists we return the payload instead of making another getRecord call. For this specific case, we are missing to validate the payload and never raise a the IdempotencyValidationException.
|
if (e.hasItem()) { |
|
DataRecord existingRecord = itemToRecord(e.item()); |
|
throw new IdempotencyItemAlreadyExistsException( |
|
"Failed to put record for already existing idempotency key: " + record.getIdempotencyKey() |
|
+ ". Existing record: " + existingRecord, |
|
e, existingRecord); |
|
} |
Code snippet
Possible Solution
Add payload validation to a catch block in BasePersistenceStore.java.
Steps to Reproduce
Enable payload validation and send two payloads with different fields for the same idempotency key.
Powertools for AWS Lambda (Java) version
latest
AWS Lambda function runtime
Java 21
Debugging logs
Expected Behaviour
When enabling JMESPath payload validation in the Idempotency utility (https://docs.aws.amazon.com/powertools/java/latest/utilities/idempotency/#payload-validation) I expect that an
IdempotencyValidationExceptionis thrown when the expected field does not match the value of the cached field for this idempotency key.Current Behaviour
This exception is not thrown in all cases anymore after introducing an optimization to save DynamoDB calls in PR #1821.
We are optimistically calling the
putRecordoperation and if this fails because the key already exists we return the payload instead of making anothergetRecordcall. For this specific case, we are missing to validate the payload and never raise a theIdempotencyValidationException.powertools-lambda-java/powertools-idempotency/powertools-idempotency-dynamodb/src/main/java/software/amazon/lambda/powertools/idempotency/persistence/dynamodb/DynamoDBPersistenceStore.java
Lines 232 to 238 in 71c632b
Code snippet
Possible Solution
Add payload validation to a catch block in
BasePersistenceStore.java.Steps to Reproduce
Enable payload validation and send two payloads with different fields for the same idempotency key.
Powertools for AWS Lambda (Java) version
latest
AWS Lambda function runtime
Java 21
Debugging logs