Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions aws_lambda_powertools/utilities/idempotency/idempotency.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
IdempotencyInconsistentStateError,
IdempotencyItemAlreadyExistsError,
IdempotencyItemNotFoundError,
IdempotencyKeyError,
IdempotencyPersistenceLayerError,
IdempotencyValidationError,
)
Expand Down Expand Up @@ -132,6 +133,8 @@ def handle(self) -> Any:
# We call save_inprogress first as an optimization for the most common case where no idempotent record
# already exists. If it succeeds, there's no need to call get_record.
self.persistence_store.save_inprogress(event=self.event, context=self.context)
except IdempotencyKeyError as e:
raise e
except IdempotencyItemAlreadyExistsError:
# Now we know the item already exists, we can retrieve it
record = self._get_idempotency_record()
Expand Down
17 changes: 17 additions & 0 deletions tests/functional/idempotency/test_idempotency.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,3 +828,20 @@ def lambda_handler(event, context):
stubber.assert_no_pending_responses()
stubber.deactivate()
assert "Failed to save in progress record to idempotency store" == e.value.args[0]


def test_handler_raise_idempotency_key_error(persistence_store: DynamoDBPersistenceLayer, lambda_context):
# GIVEN raise_on_no_idempotency_key is True
idempotency_config = IdempotencyConfig(event_key_jmespath="idemKey", raise_on_no_idempotency_key=True)

# WHEN handling the idempotent call
# AND save_inprogress raises a IdempotencyKeyError
@idempotent(persistence_store=persistence_store, config=idempotency_config)
def handler(event, context):
raise ValueError("Should not be raised")

# THEN idempotent should re-raise the IdempotencyKeyError
with pytest.raises(IdempotencyKeyError) as e:
handler({}, lambda_context)

assert "No data found to create a hashed idempotency_key" == e.value.args[0]