Skip to content

Commit

Permalink
fix(lambda): bundling docker image does not exist for Go runtime (#9465)
Browse files Browse the repository at this point in the history
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


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Niranjan Jayakar authored and Elad Ben-Israel committed Aug 10, 2020
1 parent dc6dbaa commit a7ead62
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
24 changes: 17 additions & 7 deletions packages/@aws-cdk/aws-lambda/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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-<runtime>" from https://hub.docker.com/u/amazon
*/
readonly bundlingDockerImage?: string;
}

export enum RuntimeFamily {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -158,17 +170,15 @@ 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;

constructor(name: string, family?: RuntimeFamily, props: LambdaRuntimeProps = { }) {
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);
}
Expand Down
17 changes: 17 additions & 0 deletions packages/@aws-cdk/aws-lambda/test/test.runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
});

0 comments on commit a7ead62

Please sign in to comment.