Skip to content

Commit

Permalink
fix(idempotency): Correctly handle save_inprogress errors (#313)
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Brewer authored Mar 6, 2021
1 parent 8b6a68b commit b6e61e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions aws_lambda_powertools/utilities/idempotency/idempotency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
22 changes: 22 additions & 0 deletions tests/functional/idempotency/test_idempotency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]

0 comments on commit b6e61e2

Please sign in to comment.