Skip to content

Bug: using an array for EventKeyJMESPath in idempotency module causes an error #1419

Closed
@jeromevdl

Description

@jeromevdl

What were you trying to accomplish?

When using an array to select multiple fields in the payload to build the idempotency key, an exception is thrown: No data found to create a hashed idempotency key

Expected Behavior

When using an array for EventKeyJMESPath (e.g. "[field1, field2]") to select multiple elements in a payload, idempotency module should take the fields specified in the array.

Current Behavior

An error is thrown: No data found to create a hashed idempotency key (code here)

Possible Solution

In BasePersistenceStore, replace:

    private boolean isMissingIdemPotencyKey(JsonNode data) {
        if (data.isContainerNode()) {
            Stream<Map.Entry<String, JsonNode>> stream =
                    StreamSupport.stream(Spliterators.spliteratorUnknownSize(data.fields(), Spliterator.ORDERED),
                            false);
            return stream.allMatch(e -> e.getValue().isNull());
        }
        return data.isNull();
    }

with (note the data.elements instead of fields):

    private boolean isMissingIdemPotencyKey(JsonNode data) {
        if (data.isContainerNode()) {
            Stream<JsonNode> stream =
                    StreamSupport.stream(Spliterators.spliteratorUnknownSize(data.elements(), Spliterator.ORDERED),
                            false);
            return stream.allMatch(JsonNode::isNull);
        }
        return data.isNull();
    }

Environment

  • Powertools for AWS Lambda (Java) version used: 1.17.0
  • Packaging format (Layers, Maven/Gradle): maven
  • AWS Lambda function runtime: Java17
  • Debugging logs

How to enable debug mode**

{
    "timestamp": "2023-09-05T16:02:26.409+0000UTC",
    "instant": {
        "epochSecond": 1693929746,
        "nanoOfSecond": 409000000
    },
    "thread": "main",
    "level": "ERROR",
    "loggerName": "com.amazonaws.powertools.workshop.Module1Handler",
    "message": "An unexpected error occurred",
    "thrown": {
        "message": "No data found to create a hashed idempotency key",
        "name": "software.amazon.lambda.powertools.idempotency.exceptions.IdempotencyKeyException",
        "extendedStackTrace": [
            {
                "class": "software.amazon.lambda.powertools.idempotency.persistence.BasePersistenceStore",
                "method": "getHashedIdempotencyKey",
                "file": "BasePersistenceStore.java",
                "line": 247
            },
            {
                "class": "software.amazon.lambda.powertools.idempotency.persistence.BasePersistenceStore",
                "method": "saveInProgress",
                "file": "BasePersistenceStore.java",
                "line": 150
            },
            {
                "class": "software.amazon.lambda.powertools.idempotency.internal.IdempotencyHandler",
                "method": "processIdempotency",
                "file": "IdempotencyHandler.java",
                "line": 90
            },
            {
                "class": "software.amazon.lambda.powertools.idempotency.internal.IdempotencyHandler",
                "method": "handle",
                "file": "IdempotencyHandler.java",
                "line": 72
            },
            {
                "class": "software.amazon.lambda.powertools.idempotency.internal.IdempotentAspect",
                "method": "around",
                "file": "IdempotentAspect.java",
                "line": 79
            },

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpriority:2High - core feature or affects 60% of the userssize/S

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions