From 7300f2eee9e1593eef271d7a953edf80a8962e08 Mon Sep 17 00:00:00 2001 From: Reagan Elm <1347066+relm923@users.noreply.github.com> Date: Mon, 28 Feb 2022 12:36:06 -0500 Subject: [PATCH] fix(aws-lambda-python): skip default docker build when image passed (#19143) #18082 added the ability to pass bundling parameters to `PythonFunction`'s. Currently when the `image` parameters is passed both the passed image and the default image are built even though the default image is not used ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- packages/@aws-cdk/aws-lambda-python/lib/bundling.ts | 3 +-- packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts index bd2020a5a228b..28afa880602fc 100644 --- a/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts +++ b/packages/@aws-cdk/aws-lambda-python/lib/bundling.ts @@ -70,14 +70,13 @@ export class Bundling implements CdkBundlingOptions { outputDir: outputPath, }); - const defaultImage = DockerImage.fromBuild(path.join(__dirname, '../lib'), { + this.image = image ?? DockerImage.fromBuild(path.join(__dirname, '../lib'), { buildArgs: { ...props.buildArgs ?? {}, IMAGE: runtime.bundlingImage.image, }, platform: architecture.dockerPlatform, }); - this.image = image ?? defaultImage; this.command = ['bash', '-c', chain(bundlingCommands)]; this.environment = props.environment; } diff --git a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts index a75ecc8625960..6bf90aeb090a1 100644 --- a/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-python/test/bundling.test.ts @@ -211,6 +211,7 @@ test('Bundling a function with custom bundling image', () => { }), })); + expect(DockerImage.fromBuild).toHaveBeenCalledTimes(1); expect(DockerImage.fromBuild).toHaveBeenCalledWith(expect.stringMatching(entry)); });