File tree 2 files changed +20
-0
lines changed
aws_lambda_powertools/utilities/idempotency
tests/functional/idempotency
2 files changed +20
-0
lines changed Original file line number Diff line number Diff line change 11
11
IdempotencyInconsistentStateError ,
12
12
IdempotencyItemAlreadyExistsError ,
13
13
IdempotencyItemNotFoundError ,
14
+ IdempotencyKeyError ,
14
15
IdempotencyPersistenceLayerError ,
15
16
IdempotencyValidationError ,
16
17
)
@@ -132,6 +133,8 @@ def handle(self) -> Any:
132
133
# We call save_inprogress first as an optimization for the most common case where no idempotent record
133
134
# already exists. If it succeeds, there's no need to call get_record.
134
135
self .persistence_store .save_inprogress (event = self .event , context = self .context )
136
+ except IdempotencyKeyError :
137
+ raise
135
138
except IdempotencyItemAlreadyExistsError :
136
139
# Now we know the item already exists, we can retrieve it
137
140
record = self ._get_idempotency_record ()
Original file line number Diff line number Diff line change @@ -828,3 +828,20 @@ def lambda_handler(event, context):
828
828
stubber .assert_no_pending_responses ()
829
829
stubber .deactivate ()
830
830
assert "Failed to save in progress record to idempotency store" == e .value .args [0 ]
831
+
832
+
833
+ def test_handler_raise_idempotency_key_error (persistence_store : DynamoDBPersistenceLayer , lambda_context ):
834
+ # GIVEN raise_on_no_idempotency_key is True
835
+ idempotency_config = IdempotencyConfig (event_key_jmespath = "idemKey" , raise_on_no_idempotency_key = True )
836
+
837
+ # WHEN handling the idempotent call
838
+ # AND save_inprogress raises a IdempotencyKeyError
839
+ @idempotent (persistence_store = persistence_store , config = idempotency_config )
840
+ def handler (event , context ):
841
+ raise ValueError ("Should not be raised" )
842
+
843
+ # THEN idempotent should re-raise the IdempotencyKeyError
844
+ with pytest .raises (IdempotencyKeyError ) as e :
845
+ handler ({}, lambda_context )
846
+
847
+ assert "No data found to create a hashed idempotency_key" == e .value .args [0 ]
You can’t perform that action at this time.
0 commit comments