diff --git a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/lambda.driver.ts b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/lambda.driver.ts index 808e03a6df7..ccc97706f6c 100644 --- a/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/lambda.driver.ts +++ b/packages/twenty-server/src/engine/core-modules/logic-function/logic-function-drivers/drivers/lambda.driver.ts @@ -17,6 +17,7 @@ import { type ListLayerVersionsCommandInput, LogType, PublishLayerVersionCommand, + ResourceConflictException, ResourceNotFoundException, UpdateFunctionConfigurationCommand, waitUntilFunctionActiveV2, @@ -983,6 +984,7 @@ export class LambdaDriver implements LogicFunctionDriver { const canSkip = isDefined(lambdaExecutor) && + lambdaExecutor.Configuration?.State === 'Active' && !flatApplication.isSdkLayerStale && this.hasExpectedLayers({ lambdaExecutor, @@ -1198,6 +1200,17 @@ export class LambdaDriver implements LogicFunctionDriver { ); } + if (error instanceof ResourceConflictException) { + this.logger.warn( + `Lambda function '${flatLogicFunction.id}' is not yet active (state conflict). Retrying after waiting for active state.`, + ); + + throw new LogicFunctionException( + `Function '${flatLogicFunction.id}' is not ready for invocation (currently updating or pending)`, + LogicFunctionExceptionCode.LOGIC_FUNCTION_EXECUTION_FAILED, + ); + } + if (error instanceof LogicFunctionException) { throw error; }