@@ -400,11 +400,6 @@ after this timestamp, and the record is still marked `INPROGRESS`, we execute th
400
400
already expired. This means that if an invocation expired during execution, it will be quickly executed again on the
401
401
next retry.
402
402
403
- ???+ info "Info: Calculating the remaining available time"
404
- For now this only works with the ` idempotent ` decorator. At the moment we
405
- don't have access to the Lambda context when using the
406
- ` idempotent_function ` so enabling this option is a no-op in that scenario.
407
-
408
403
<center >
409
404
``` mermaid
410
405
sequenceDiagram
@@ -439,6 +434,32 @@ sequenceDiagram
439
434
<i >Idempotent sequence for Lambda timeouts</i >
440
435
</center >
441
436
437
+ ???+ info "Info: Calculating the remaining available time"
438
+ When using the ` idempotent ` decorator, we captura and calculate the remaining available time for you.
439
+ However, when using the ` idempotent_function ` , the functionality doesn't work out of the box. You'll
440
+ need to register the Lambda context on your handler:
441
+
442
+ ``` python hl_lines="8 16" title="Registering the Lambda context"
443
+ from aws_lambda_powertools.utilities.data_classes.sqs_event import SQSRecord
444
+ from aws_lambda_powertools.utilities.idempotency import (
445
+ IdempotencyConfig, idempotent_function
446
+ )
447
+
448
+ persistence_layer = DynamoDBPersistenceLayer(table_name = " ..." )
449
+
450
+ config = IdempotencyConfig()
451
+
452
+ @idempotent_function (data_keyword_argument = " record" , persistence_store = persistence_layer, config = config)
453
+ def record_handler (record : SQSRecord):
454
+ return {" message" : record[" body" ]}
455
+
456
+
457
+ def lambda_handler (event , context ):
458
+ config.register_lambda_context(context)
459
+
460
+ return record_handler(event)
461
+ ```
462
+
442
463
### Handling exceptions
443
464
444
465
If you are using the ` idempotent ` decorator on your Lambda handler, any unhandled exceptions that are raised during the code execution will cause ** the record in the persistence layer to be deleted** .
0 commit comments