File tree 2 files changed +26
-0
lines changed
aws_lambda_powertools/utilities/idempotency
tests/functional/idempotency
2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change @@ -135,6 +135,8 @@ def handle(self) -> Any:
135
135
# Now we know the item already exists, we can retrieve it
136
136
record = self ._get_idempotency_record ()
137
137
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
138
140
139
141
return self ._call_lambda_handler ()
140
142
Original file line number Diff line number Diff line change @@ -775,3 +775,27 @@ def test_custom_jmespath_function_overrides_builtin_functions(
775
775
# WHEN calling _get_hashed_idempotency_key
776
776
# THEN raise unknown function
777
777
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 ]
You can’t perform that action at this time.
0 commit comments