diff --git a/aws_lambda_powertools/utilities/idempotency/idempotency.py b/aws_lambda_powertools/utilities/idempotency/idempotency.py index 06d77a9fd72..750ed360f0b 100644 --- a/aws_lambda_powertools/utilities/idempotency/idempotency.py +++ b/aws_lambda_powertools/utilities/idempotency/idempotency.py @@ -135,6 +135,8 @@ def handle(self) -> Any: # Now we know the item already exists, we can retrieve it record = self._get_idempotency_record() return self._handle_for_status(record) + except Exception as exc: + raise IdempotencyPersistenceLayerError("Failed to save in progress record to idempotency store") from exc return self._call_lambda_handler() diff --git a/tests/functional/idempotency/test_idempotency.py b/tests/functional/idempotency/test_idempotency.py index 6def9b4868a..2f541587227 100644 --- a/tests/functional/idempotency/test_idempotency.py +++ b/tests/functional/idempotency/test_idempotency.py @@ -775,3 +775,25 @@ def test_custom_jmespath_function_overrides_builtin_functions( # WHEN calling _get_hashed_idempotency_key # THEN raise unknown function persistence_store._get_hashed_idempotency_key({}) + + +def test_idempotent_lambda_save_inprogress_error(persistence_store: DynamoDBPersistenceLayer): + # GIVEN a miss configured persistence layer + # like no table was created for the idempotency persistence layer + stubber = stub.Stubber(persistence_store.table.meta.client) + stubber.add_client_error("put_item", "ResourceNotFoundException") + stubber.activate() + + @idempotent(persistence_store=persistence_store) + def lambda_handler(event, context): + return {} + + # WHEN handling the idempotent call + # AND save_inprogress raises a ClientError + with pytest.raises(IdempotencyPersistenceLayerError) as e: + lambda_handler({}, {}) + + # THEN idempotent should raise an IdempotencyPersistenceLayerError + stubber.assert_no_pending_responses() + stubber.deactivate() + assert "Failed to save in progress record to idempotency store" == e.value.args[0]