Skip to content

Commit

Permalink
fix: Don't allow wrong OS for Lambda runner provider (#422)
Browse files Browse the repository at this point in the history
See #420
  • Loading branch information
kichik committed Sep 13, 2023
1 parent 956722a commit c01e8a7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/providers/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ export class LambdaRunnerProvider extends BaseProvider implements IRunnerProvide
* Base Docker image: `public.ecr.aws/lambda/nodejs:14-x86_64` or `public.ecr.aws/lambda/nodejs:14-arm64`
*/
public static imageBuilder(scope: Construct, id: string, props?: RunnerImageBuilderProps) {
if (props?.os && !Os.LINUX_AMAZON_2.is(props.os) && !props?.baseDockerImage) {
// TODO we can support Ubuntu by building our own image https://docs.aws.amazon.com/lambda/latest/dg/nodejs-image.html#nodejs-image-clients
throw new Error('Lambda runner provider only supports Amazon Linux 2. Use a different provider or specify a custom `baseDockerImage` that supports your desired OS.');
}

let baseDockerImage = 'public.ecr.aws/lambda/nodejs:14-x86_64';
if (props?.architecture === Architecture.ARM64) {
baseDockerImage = 'public.ecr.aws/lambda/nodejs:14-arm64';
Expand Down
16 changes: 16 additions & 0 deletions test/imagebuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,3 +302,19 @@ test('Lambda default image builder has GitHub Runner and Lambda entry point', ()
},
});
});

test('Lambda image builder only accepts AMZL2', () => {
const app = new cdk.App();
const stack = new cdk.Stack(app, 'test');

expect(() => {
LambdaRunnerProvider.imageBuilder(stack, 'builder', {
os: Os.LINUX_UBUNTU,
});
}).toThrowError('Lambda runner provider only supports Amazon Linux 2');

LambdaRunnerProvider.imageBuilder(stack, 'builder', {
os: Os.LINUX_UBUNTU,
baseDockerImage: 'some-fake-ubuntu-image',
});
});

0 comments on commit c01e8a7

Please sign in to comment.