diff --git a/aws_lambda/aws_lambda.py b/aws_lambda/aws_lambda.py index 0b5ca88..2859de1 100644 --- a/aws_lambda/aws_lambda.py +++ b/aws_lambda/aws_lambda.py @@ -704,10 +704,14 @@ def update_function( Publish=True, ) - # Wait for function to be updated + # Wait for function code to be updated waiter = client.get_waiter('function_updated') + print("Waiting for code update to complete...") waiter.wait(FunctionName=cfg.get("function_name")) + # Add a short delay to allow propagation + time.sleep(5) + kwargs = { "FunctionName": cfg.get("function_name"), "Role": role, @@ -745,7 +749,21 @@ def update_function( }, ) - ret = client.update_function_configuration(**kwargs) + # Retry configuration update in case of conflicts + retries = 5 + for attempt in range(retries): + try: + print("Updating function configuration...") + ret = client.update_function_configuration(**kwargs) + break + except client.exceptions.ResourceConflictException as e: + print(f"Conflict detected. Retrying... ({attempt + 1}/{retries})") + time.sleep(10) # Wait before retrying + else: + raise Exception(f"Failed to update function configuration after {retries} retries.") + + # Add a short delay to allow propagation + time.sleep(5) concurrency = get_concurrency(cfg) if concurrency > 0: