Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 32 additions & 1 deletion service/src/providers/aws-lambda/deploy.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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!,
Expand Down
8 changes: 4 additions & 4 deletions service/src/queues/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
)}`
Expand All @@ -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.'
});
}
Expand Down Expand Up @@ -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}`
});
}
Expand Down