Skip to content

Commit b6e61e2

Browse files
author
Michael Brewer
authored
fix(idempotency): Correctly handle save_inprogress errors (#313)
1 parent 8b6a68b commit b6e61e2

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Diff for: 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

Diff for: tests/functional/idempotency/test_idempotency.py

+22
Original file line numberDiff line numberDiff line change
@@ -775,3 +775,25 @@ 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+
def test_idempotent_lambda_save_inprogress_error(persistence_store: DynamoDBPersistenceLayer):
781+
# GIVEN a miss configured persistence layer
782+
# like no table was created for the idempotency persistence layer
783+
stubber = stub.Stubber(persistence_store.table.meta.client)
784+
stubber.add_client_error("put_item", "ResourceNotFoundException")
785+
stubber.activate()
786+
787+
@idempotent(persistence_store=persistence_store)
788+
def lambda_handler(event, context):
789+
return {}
790+
791+
# WHEN handling the idempotent call
792+
# AND save_inprogress raises a ClientError
793+
with pytest.raises(IdempotencyPersistenceLayerError) as e:
794+
lambda_handler({}, {})
795+
796+
# THEN idempotent should raise an IdempotencyPersistenceLayerError
797+
stubber.assert_no_pending_responses()
798+
stubber.deactivate()
799+
assert "Failed to save in progress record to idempotency store" == e.value.args[0]

0 commit comments

Comments
 (0)