Skip to content

Commit 88a0a93

Browse files
author
Michael Brewer
committed
fix(idempotency): Handle save_inprogress errors as a IdempotencyPersistenceLayerError
1 parent 8b6a68b commit 88a0a93

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

aws_lambda_powertools/utilities/idempotency/idempotency.py

+2
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ def handle(self) -> Any:
135135
# Now we know the item already exists, we can retrieve it
136136
record = self._get_idempotency_record()
137137
return self._handle_for_status(record)
138+
except Exception as exc:
139+
raise IdempotencyPersistenceLayerError("Failed to save in progress record to idempotency store") from exc
138140

139141
return self._call_lambda_handler()
140142

tests/functional/idempotency/test_idempotency.py

+24
Original file line numberDiff line numberDiff line change
@@ -775,3 +775,27 @@ def test_custom_jmespath_function_overrides_builtin_functions(
775775
# WHEN calling _get_hashed_idempotency_key
776776
# THEN raise unknown function
777777
persistence_store._get_hashed_idempotency_key({})
778+
779+
780+
@pytest.mark.parametrize("config_with_validation", [{"use_local_cache": False}], indirect=True)
781+
def test_idempotent_lambda_save_inprogress_error(
782+
config_with_validation: IdempotencyConfig, persistence_store: DynamoDBPersistenceLayer
783+
):
784+
"""
785+
Test idempotent decorator where event with matching event key has already been successfully processed
786+
"""
787+
788+
stubber = stub.Stubber(persistence_store.table.meta.client)
789+
stubber.add_client_error("put_item", "ClientError")
790+
stubber.activate()
791+
792+
@idempotent(config=config_with_validation, persistence_store=persistence_store)
793+
def lambda_handler(event, context):
794+
return {}
795+
796+
with pytest.raises(IdempotencyPersistenceLayerError) as e:
797+
lambda_handler({}, {})
798+
799+
stubber.assert_no_pending_responses()
800+
stubber.deactivate()
801+
assert "Failed to save in progress record to idempotency store" == e.value.args[0]

0 commit comments

Comments
 (0)