diff --git a/service/src/providers/aws-lambda/deploy.ts b/service/src/providers/aws-lambda/deploy.ts index 53d62db..265e26e 100644 --- a/service/src/providers/aws-lambda/deploy.ts +++ b/service/src/providers/aws-lambda/deploy.ts @@ -1,5 +1,10 @@ -import { Runtime as AwsRuntime, CreateFunctionCommand } from '@aws-sdk/client-lambda'; +import { + Runtime as AwsRuntime, + CreateFunctionCommand, + GetFunctionCommand +} from '@aws-sdk/client-lambda'; import type { FunctionBayRuntimeConfig } from '@function-bay/types'; +import { delay } from '@lowerdeck/delay'; import type { Function, FunctionDeployment, Runtime } from '../../../prisma/generated/client'; import { lambdaClient } from './lambda'; import { ensureLambdaExecutionRole } from './role'; @@ -78,6 +83,32 @@ export let deployFunction = async (d: { }) ); + if (!res.FunctionArn || !res.FunctionName) { + throw new Error('Failed to deploy function'); + } + + await delay(2500); + + let func = await lambdaClient.send( + new GetFunctionCommand({ + FunctionName: res.FunctionName + }) + ); + + while (func.Configuration?.State == 'Pending') { + await delay(1000); + + func = await lambdaClient.send( + new GetFunctionCommand({ + FunctionName: res.FunctionName + }) + ); + } + + if (func.Configuration?.State == 'Failed') { + throw new Error('Function deployment failed: ' + func.Configuration.StateReason); + } + return { providerData: { functionArn: res.FunctionArn!, diff --git a/service/src/queues/build.ts b/service/src/queues/build.ts index 7bc8edb..17126bc 100644 --- a/service/src/queues/build.ts +++ b/service/src/queues/build.ts @@ -139,7 +139,7 @@ let workflowFinishedBuildQueueProcessor = workflowFinishedBuildQueue.process(asy if (!manifestArtifact || !outputArtifact) { await errorQueue.add({ deploymentId: data.deploymentId, - code: 'build_runtime_error', + code: 'function_bay.build_runtime_error', message: 'The build runtime did not produce the expected artifacts.' }); return; @@ -156,7 +156,7 @@ let workflowFinishedBuildQueueProcessor = workflowFinishedBuildQueue.process(asy if (!valRes.success) { await errorQueue.add({ deploymentId: data.deploymentId, - code: 'build_invalid_manifest', + code: 'function_bay.build_invalid_manifest', message: `The build runtime produced an invalid manifest: ${JSON.stringify( valRes.errors )}` @@ -177,7 +177,7 @@ let workflowFinishedBuildQueueProcessor = workflowFinishedBuildQueue.process(asy } else { await errorQueue.add({ deploymentId: data.deploymentId, - code: 'build_failed', + code: 'function_bay.build_failed', message: 'The build workflow run failed.' }); } @@ -253,7 +253,7 @@ let deployToRuntimeQueueProcessor = deployToRuntimeQueue.process(async data => { await errorQueue.add({ deploymentId: deployment.id, - code: 'deploy_runtime_error', + code: 'function_bay.deploy_runtime_error', message: `Error deploying function to runtime: ${err.message}` }); }