diff --git a/aws_lambda_powertools/utilities/idempotency/persistence/base.py b/aws_lambda_powertools/utilities/idempotency/persistence/base.py index 95736634ca6..8f41337cf5f 100644 --- a/aws_lambda_powertools/utilities/idempotency/persistence/base.py +++ b/aws_lambda_powertools/utilities/idempotency/persistence/base.py @@ -301,7 +301,10 @@ def save_inprogress(self, data: Dict[str, Any], remaining_time_in_millis: Option payload_hash=self._get_hashed_payload(data=data), ) - if remaining_time_in_millis: + # When Lambda kills the container after timeout, the remaining_time_in_millis is 0, which is considered False. + # Therefore, we need to check if remaining_time_in_millis is not None (>=0) to handle this case. + # See: https://github.com/aws-powertools/powertools-lambda-python/issues/4759 + if remaining_time_in_millis is not None: now = datetime.datetime.now() period = datetime.timedelta(milliseconds=remaining_time_in_millis) timestamp = (now + period).timestamp()