Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add lambda read timeout retries
Signed-off-by: hkuepers <hanno.kuepers@ratepay.com>
  • Loading branch information
hkuepers committed May 21, 2025
commit 7a217d25b74ce655001cc2a75658433428a1072b
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

DEFAULT_BATCH_SIZE = 10_000
DEFAULT_TIMEOUT = 600
LAMBDA_TIMEOUT_RETRIES = 5

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -225,7 +226,7 @@ def _materialize_one(
logger.info("Invoking materialization for %s", path)
futures.append(
executor.submit(
self.lambda_client.invoke,
self.invoke_with_retries,
FunctionName=self.lambda_name,
InvocationType="RequestResponse",
Payload=json.dumps(payload),
Expand Down Expand Up @@ -253,3 +254,20 @@ def _materialize_one(
if not not_done
else MaterializationJobStatus.ERROR,
)

def invoke_with_retries(self, **kwargs):
"""Invoke the Lambda function and retry if it times out.

The Lambda function may time out initially if many values are updated
and DynamoDB throttles requests. As soon as the DynamoDB tables
are scaled up, the Lambda function can succeed upon retry with higher
throughput.

"""
retries = 0
while retries < LAMBDA_TIMEOUT_RETRIES:
response = self.lambda_client.invoke(**kwargs)
if "Task timed out after" not in json.loads(response["Payload"].read()):
break
retries += 1
return response