Skip to content

Commit a7ead62

Browse files
Niranjan JayakarElad Ben-Israel
Niranjan Jayakar
authored and
Elad Ben-Israel
committed
fix(lambda): bundling docker image does not exist for Go runtime (#9465)
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*
1 parent dc6dbaa commit a7ead62

File tree

2 files changed

+34
-7
lines changed

2 files changed

+34
-7
lines changed

packages/@aws-cdk/aws-lambda/lib/runtime.ts

+17-7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ export interface LambdaRuntimeProps {
66
* @default false
77
*/
88
readonly supportsInlineCode?: boolean;
9+
10+
/**
11+
* The Docker image name to be used for bundling in this runtime.
12+
* @default - the latest docker image "amazon/aws-sam-cli-build-image-<runtime>" from https://hub.docker.com/u/amazon
13+
*/
14+
readonly bundlingDockerImage?: string;
915
}
1016

1117
export enum RuntimeFamily {
@@ -113,17 +119,23 @@ export class Runtime {
113119
/**
114120
* The .NET Core 2.1 runtime (dotnetcore2.1)
115121
*/
116-
public static readonly DOTNET_CORE_2_1 = new Runtime('dotnetcore2.1', RuntimeFamily.DOTNET_CORE);
122+
public static readonly DOTNET_CORE_2_1 = new Runtime('dotnetcore2.1', RuntimeFamily.DOTNET_CORE, {
123+
bundlingDockerImage: 'lambci/lambda:build-dotnetcore2.1',
124+
});
117125

118126
/**
119127
* The .NET Core 3.1 runtime (dotnetcore3.1)
120128
*/
121-
public static readonly DOTNET_CORE_3_1 = new Runtime('dotnetcore3.1', RuntimeFamily.DOTNET_CORE);
129+
public static readonly DOTNET_CORE_3_1 = new Runtime('dotnetcore3.1', RuntimeFamily.DOTNET_CORE, {
130+
bundlingDockerImage: 'lambci/lambda:build-dotnetcore3.1',
131+
});
122132

123133
/**
124134
* The Go 1.x runtime (go1.x)
125135
*/
126-
public static readonly GO_1_X = new Runtime('go1.x', RuntimeFamily.GO);
136+
public static readonly GO_1_X = new Runtime('go1.x', RuntimeFamily.GO, {
137+
bundlingDockerImage: 'lambci/lambda:build-go1.x',
138+
});
127139

128140
/**
129141
* The Ruby 2.5 runtime (ruby2.5)
@@ -158,17 +170,15 @@ export class Runtime {
158170

159171
/**
160172
* The bundling Docker image for this runtime.
161-
* Points to the AWS SAM build image for this runtime.
162-
*
163-
* @see https://github.com/awslabs/aws-sam-cli
164173
*/
165174
public readonly bundlingDockerImage: BundlingDockerImage;
166175

167176
constructor(name: string, family?: RuntimeFamily, props: LambdaRuntimeProps = { }) {
168177
this.name = name;
169178
this.supportsInlineCode = !!props.supportsInlineCode;
170179
this.family = family;
171-
this.bundlingDockerImage = BundlingDockerImage.fromRegistry(`amazon/aws-sam-cli-build-image-${name}`);
180+
const imageName = props.bundlingDockerImage ?? `amazon/aws-sam-cli-build-image-${name}`;
181+
this.bundlingDockerImage = BundlingDockerImage.fromRegistry(imageName);
172182

173183
Runtime.ALL.push(this);
174184
}

packages/@aws-cdk/aws-lambda/test/test.runtime.ts

+17
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,21 @@ export = testCase({
7575

7676
test.done();
7777
},
78+
'overridde to bundlingDockerImage points to the correct image'(test: Test) {
79+
// GIVEN
80+
const runtime = new lambda.Runtime('my-runtime-name', undefined, {
81+
bundlingDockerImage: 'my-docker-image',
82+
});
83+
84+
// THEN
85+
test.equal(runtime.bundlingDockerImage.image, 'my-docker-image');
86+
87+
test.done();
88+
},
89+
'dotnetcore and go have overridden images'(test: Test) {
90+
test.equal(lambda.Runtime.DOTNET_CORE_3_1.bundlingDockerImage.image, 'lambci/lambda:build-dotnetcore3.1');
91+
test.equal(lambda.Runtime.DOTNET_CORE_2_1.bundlingDockerImage.image, 'lambci/lambda:build-dotnetcore2.1');
92+
test.equal(lambda.Runtime.GO_1_X.bundlingDockerImage.image, 'lambci/lambda:build-go1.x');
93+
test.done();
94+
},
7895
});

0 commit comments

Comments
 (0)