Skip to content

Commit

Permalink
feat(@aws-cdk/aws-lambda): Use bundling images from ECR public gallery
Browse files Browse the repository at this point in the history
fixes aws#11296
  • Loading branch information
Philipp Garbe committed Mar 29, 2021
1 parent aa9fd9c commit 88bf77a
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda-nodejs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ used by your function. Otherwise bundling will fail.
## Local bundling

If `esbuild` is available it will be used to bundle your code in your environment. Otherwise,
bundling will happen in a [Lambda compatible Docker container](https://hub.docker.com/r/amazon/aws-sam-cli-build-image-nodejs12.x).
bundling will happen in a [Lambda compatible Docker container](https://gallery.ecr.aws/sam/build-nodejs12.x).

For macOS the recommendend approach is to install `esbuild` as Docker volume performance is really poor.

Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda-nodejs/lib/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The correct AWS SAM build image based on the runtime of the function will be
# passed as build arg. The default allows to do `docker build .` when testing.
ARG IMAGE=amazon/aws-sam-cli-build-image-nodejs12.x
ARG IMAGE=public.ecr.aws/sam/build-nodejs12.x
FROM $IMAGE

# Install yarn
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ All other properties of `lambda.Function` are supported, see also the [AWS Lambd
## Module Dependencies

If `requirements.txt` or `Pipfile` exists at the entry path, the construct will handle installing
all required modules in a [Lambda compatible Docker container](https://hub.docker.com/r/amazon/aws-sam-cli-build-image-python3.7)
all required modules in a [Lambda compatible Docker container](https://gallery.ecr.aws/sam/build-python3.7)
according to the `runtime`.

**Lambda with a requirements.txt**
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda-python/lib/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The correct AWS SAM build image based on the runtime of the function will be
# passed as build arg. The default allows to do `docker build .` when testing.
ARG IMAGE=amazon/aws-sam-cli-build-image-python3.7
ARG IMAGE=public.ecr.aws/sam/build-python3.7
FROM $IMAGE

# Ensure rsync is installed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The correct AWS SAM build image based on the runtime of the function will be
# passed as build arg. The default allows to do `docker build .` when testing.
ARG IMAGE=amazon/aws-sam-cli-build-image-python3.7
ARG IMAGE=public.ecr.aws/sam/build-python3.7
FROM $IMAGE

# Ensure rsync is installed
Expand Down
11 changes: 6 additions & 5 deletions packages/@aws-cdk/aws-lambda/lib/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export interface LambdaRuntimeProps {

/**
* 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
* @default - the latest docker image "amazon/public.ecr.aws/sam/build-<runtime>" from https://gallery.ecr.aws
*/
readonly bundlingDockerImage?: string;

Expand Down Expand Up @@ -219,11 +219,12 @@ export class Runtime {
*/
public readonly bundlingImage: DockerImage;

constructor(name: string, family?: RuntimeFamily, props: LambdaRuntimeProps = { }) {
constructor(name: string, family?: RuntimeFamily, props: LambdaRuntimeProps = {}) {
this.name = name;
this.supportsInlineCode = !!props.supportsInlineCode;
this.family = family;
const imageName = props.bundlingDockerImage ?? `amazon/aws-sam-cli-build-image-${name}`;

const imageName = props.bundlingDockerImage ?? `public.ecr.aws/sam/build-${name}`;
this.bundlingDockerImage = DockerImage.fromRegistry(imageName);
this.bundlingImage = this.bundlingDockerImage;
this.supportsCodeGuruProfiling = props.supportsCodeGuruProfiling ?? false;
Expand All @@ -237,7 +238,7 @@ export class Runtime {

public runtimeEquals(other: Runtime): boolean {
return other.name === this.name &&
other.family === this.family &&
other.supportsInlineCode === this.supportsInlineCode;
other.family === this.family &&
other.supportsInlineCode === this.supportsInlineCode;
}
}
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-lambda/test/runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('runtime', () => {
const runtime = new lambda.Runtime('my-runtime-name');

// THEN
expect(runtime.bundlingDockerImage.image).toEqual('amazon/aws-sam-cli-build-image-my-runtime-name');
expect(runtime.bundlingDockerImage.image).toEqual('public.ecr.aws/sam/build-my-runtime-name');
});

test('overridde to bundlingDockerImage points to the correct image', () => {
Expand Down

0 comments on commit 88bf77a

Please sign in to comment.