Skip to content

Bug: Idempotency misses JMESPath payload validation in some cases #2260

@phipag

Description

@phipag

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

N/A

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

Metadata

Metadata

Assignees

Labels

Type

Projects

Status

Working on it

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions