You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This persistence layer is built-in, and you can either use an existing DynamoDB table or create a new one dedicated for idempotency state (recommended).
404
405
405
-
```python hl_lines="5-9" title="Customizing DynamoDBPersistenceLayer to suit your table structure"
406
+
```python hl_lines="5-10" title="Customizing DynamoDBPersistenceLayer to suit your table structure"
406
407
from aws_lambda_powertools.utilities.idempotency import DynamoDBPersistenceLayer
**payload_validation_jmespath**|`""`| JMESPath expression to validate whether certain parameters have changed in the event while the event payload
441
444
**raise_on_no_idempotency_key**|`False`| Raise exception if no idempotency key was found in the request
442
445
**expires_after_seconds**|3600| The number of seconds to wait before a record is expired
446
+
**expires_in_progress**|`False`| Enables expiry of invocations that time out during execution
443
447
**use_local_cache**|`False`| Whether to locally cache idempotency results
444
448
**local_cache_max_items**|256| Max number of items to store in local cache
445
449
**hash_function**|`md5`| Function to use for calculating hashes, as provided by [hashlib](https://docs.python.org/3/library/hashlib.html) in the standard library.
@@ -853,6 +857,54 @@ class DynamoDBPersistenceLayer(BasePersistenceLayer):
853
857
854
858
For example, the `_put_record` method needs to raise an exception if a non-expired record already exists in the data store with a matching key.
855
859
860
+
### Expiring in-progress invocations
861
+
862
+
The default behavior when a Lambda invocation times out isfor the event to stay locked until `expire_seconds` have passed. Powertools
863
+
has no way of knowing if it's safe to retry the operation in this scenario, so we assume the safest approach: to not
864
+
retry the operation.
865
+
866
+
However, certain types of invocation have less strict requirements, and can benefit from faster expiry of invocations. Ideally, we
867
+
can make an in-progress invocation expire as soon as the [Lambda invocation expires](https://aws.amazon.com/premiumsupport/knowledge-center/lambda-verify-invocation-timeouts/).
868
+
869
+
When using this option, powertools will calculate the remaining available time for the invocation, and save it on the idempotency record.
870
+
This way, if a second invocation happens after this timestamp, and the record is stil marked `INPROGRESS`, we execute the invocation again
871
+
asif it was already expired. This means that if an invocation expired during execution, it will be quickly executed again on the nexttry.
872
+
873
+
This setting introduces no change on the regular behavior where if an invocation succeeds, the results are cached for`expire_seconds` seconds.
874
+
875
+
???+ warning "Warning"
876
+
Consider whenever you really want this behavior. Powertools can't make any garantee on which state your application was
877
+
when it time outed. Ensure that your business logic can be retried at any stage.
878
+
879
+
???+ info "Info: Calculating the remaining available time"
880
+
For now this only works with the `idempotent` decorator. At the moment we don't have access to the Lambda context when using
881
+
the `idempotent_function` so enabling this option is a no-op in that scenario.
882
+
883
+
To activate this behaviour, enable the `expires_in_progress` option on the configuration:
884
+
885
+
==="app.py"
886
+
887
+
```python hl_lines="7"
888
+
from aws_lambda_powertools.utilities.idempotency import (
0 commit comments