File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
aws_lambda_powertools/utilities/idempotency
tests/functional/idempotency Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ]
You can’t perform that action at this time.
0 commit comments