From c90623c67112d314b2cc6611d41e14668c24db84 Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Wed, 5 Aug 2020 18:24:41 +0100 Subject: [PATCH 1/2] fix(lambda): bundling docker image does not exist for Go runtime The official docker images for lambda are not available yet for Go and dotnet core runtimes. Switch back to using lambdaci in these cases. fixes #9435 --- packages/@aws-cdk/aws-lambda/lib/runtime.ts | 24 +++++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda/lib/runtime.ts b/packages/@aws-cdk/aws-lambda/lib/runtime.ts index 207d8071d996e..c8da723f06e82 100644 --- a/packages/@aws-cdk/aws-lambda/lib/runtime.ts +++ b/packages/@aws-cdk/aws-lambda/lib/runtime.ts @@ -6,6 +6,12 @@ export interface LambdaRuntimeProps { * @default false */ readonly supportsInlineCode?: boolean; + + /** + * The Docker image name to be used for bundling in this runtime. + * @default - the latest docker image "amazon/aws-sam-cli-build-image-" from https://hub.docker.com/u/amazon + */ + readonly bundlingDockerImage?: string; } export enum RuntimeFamily { @@ -113,17 +119,23 @@ export class Runtime { /** * The .NET Core 2.1 runtime (dotnetcore2.1) */ - public static readonly DOTNET_CORE_2_1 = new Runtime('dotnetcore2.1', RuntimeFamily.DOTNET_CORE); + public static readonly DOTNET_CORE_2_1 = new Runtime('dotnetcore2.1', RuntimeFamily.DOTNET_CORE, { + bundlingDockerImage: 'lambci/lambda:build-dotnetcore2.1', + }); /** * The .NET Core 3.1 runtime (dotnetcore3.1) */ - public static readonly DOTNET_CORE_3_1 = new Runtime('dotnetcore3.1', RuntimeFamily.DOTNET_CORE); + public static readonly DOTNET_CORE_3_1 = new Runtime('dotnetcore3.1', RuntimeFamily.DOTNET_CORE, { + bundlingDockerImage: 'lambci/lambda:build-dotnetcore3.1', + }); /** * The Go 1.x runtime (go1.x) */ - public static readonly GO_1_X = new Runtime('go1.x', RuntimeFamily.GO); + public static readonly GO_1_X = new Runtime('go1.x', RuntimeFamily.GO, { + bundlingDockerImage: 'lambci/lambda:build-go1.x', + }); /** * The Ruby 2.5 runtime (ruby2.5) @@ -158,9 +170,6 @@ export class Runtime { /** * The bundling Docker image for this runtime. - * Points to the AWS SAM build image for this runtime. - * - * @see https://github.com/awslabs/aws-sam-cli */ public readonly bundlingDockerImage: BundlingDockerImage; @@ -168,7 +177,8 @@ export class Runtime { this.name = name; this.supportsInlineCode = !!props.supportsInlineCode; this.family = family; - this.bundlingDockerImage = BundlingDockerImage.fromRegistry(`amazon/aws-sam-cli-build-image-${name}`); + const imageName = props.bundlingDockerImage ?? `amazon/aws-sam-cli-build-image-${name}`; + this.bundlingDockerImage = BundlingDockerImage.fromRegistry(imageName); Runtime.ALL.push(this); } From bb020cd3efee048bfb379d4f8a0e3d0d427145f6 Mon Sep 17 00:00:00 2001 From: Niranjan Jayakar Date: Thu, 6 Aug 2020 09:50:12 +0100 Subject: [PATCH 2/2] add tests --- .../@aws-cdk/aws-lambda/test/test.runtime.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/packages/@aws-cdk/aws-lambda/test/test.runtime.ts b/packages/@aws-cdk/aws-lambda/test/test.runtime.ts index df5cf230ce15c..67294babdec9d 100644 --- a/packages/@aws-cdk/aws-lambda/test/test.runtime.ts +++ b/packages/@aws-cdk/aws-lambda/test/test.runtime.ts @@ -75,4 +75,21 @@ export = testCase({ test.done(); }, + 'overridde to bundlingDockerImage points to the correct image'(test: Test) { + // GIVEN + const runtime = new lambda.Runtime('my-runtime-name', undefined, { + bundlingDockerImage: 'my-docker-image', + }); + + // THEN + test.equal(runtime.bundlingDockerImage.image, 'my-docker-image'); + + test.done(); + }, + 'dotnetcore and go have overridden images'(test: Test) { + test.equal(lambda.Runtime.DOTNET_CORE_3_1.bundlingDockerImage.image, 'lambci/lambda:build-dotnetcore3.1'); + test.equal(lambda.Runtime.DOTNET_CORE_2_1.bundlingDockerImage.image, 'lambci/lambda:build-dotnetcore2.1'); + test.equal(lambda.Runtime.GO_1_X.bundlingDockerImage.image, 'lambci/lambda:build-go1.x'); + test.done(); + }, });