Skip to content

Bug: Treat missing idempotency key as non-idempotent transaction #2465

Closed
@heitorlessa

Description

@heitorlessa

Expected Behaviour

By default, treat a transaction that is missing idempotency key as a NO-OP transaction. That means, we will continue to log a warning and will not save at the configured persistence storage layer.

This prevents mistakes when an application is designed to optionally send an unique value (e.g., X-Idempotency-Value) and NULL doesn't get a unique sentinel value (e.g., UUID) in its absence.

Current Behaviour

By default, raise_on_no_idempotency_key is set to False. This means we will log a warning when the idempotency key is missing, since we don't know if that's intentional or not. However we continue treating the transaction like we normally would, hash the None value, and save it in the persistence store.

Tests confirming behaviour

Code snippet

from aws_lambda_powertools.utilities.idempotency import (
    DynamoDBPersistenceLayer, idempotent
)

persistence_layer = DynamoDBPersistenceLayer(table_name="IdempotencyTable")
config = IdempotencyConfig(
    event_key_jmespath="headers.X-Idempotency-Value",  # Browser Might Not Send It
)

@idempotent(persistence_store=persistence_layer)
def handler(event, context):
    return {
        "message": "FIRST REQUEST",
        "statusCode": 200,
    }

Possible Solution

aws-powertools/powertools-lambda-typescript#1501

Steps to Reproduce

Calling the handler twice without the X-Idempotency-Value HTTP Header will return the first response in both requests.

Powertools for AWS Lambda (Python) version

latest

AWS Lambda function runtime

3.10

Packaging format used

Lambda Layers

Debugging logs

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingidempotencyIdempotency utility

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions