From 1ad31b8b659e7365725a04017509d41b8ccf0deb Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Mon, 28 Dec 2020 17:24:39 +0100 Subject: [PATCH 1/9] feat(lambda): Code.fromDockerBuildAsset Use the result of a Docker build as code. The runtime code is expected to be located at `/asset` in the image. Also deprecate `BundlingDockerImage` in favor of `DockerImage`. --- packages/@aws-cdk/aws-lambda-nodejs/README.md | 4 +-- packages/@aws-cdk/aws-lambda/README.md | 9 ++++-- packages/@aws-cdk/aws-lambda/lib/code.ts | 13 +++++++++ .../@aws-cdk/aws-lambda/test/code.test.ts | 23 +++++++++++++++ packages/@aws-cdk/aws-s3-assets/README.md | 6 ++-- packages/@aws-cdk/core/lib/bundling.ts | 29 ++++++++++++++++--- packages/@aws-cdk/core/test/bundling.test.ts | 23 ++++++++++++++- 7 files changed, 94 insertions(+), 13 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda-nodejs/README.md b/packages/@aws-cdk/aws-lambda-nodejs/README.md index 723ce157c6fbb..a643cac1d9cbe 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/README.md +++ b/packages/@aws-cdk/aws-lambda-nodejs/README.md @@ -145,7 +145,7 @@ new lambda.NodejsFunction(this, 'my-handler', { }, logLevel: LogLevel.SILENT, // defaults to LogLevel.WARNING keepNames: true, // defaults to false - tsconfig: 'custom-tsconfig.json' // use custom-tsconfig.json instead of default, + tsconfig: 'custom-tsconfig.json' // use custom-tsconfig.json instead of default, metafile: true, // include meta file, defaults to false banner : '/* comments */', // by default no comments are passed footer : '/* comments */', // by default no comments are passed @@ -213,7 +213,7 @@ Use `bundling.dockerImage` to use a custom Docker bundling image: ```ts new lambda.NodejsFunction(this, 'my-handler', { bundling: { - dockerImage: cdk.BundlingDockerImage.fromAsset('/path/to/Dockerfile'), + dockerImage: cdk.DockerImage.fromBuild('/path/to/Dockerfile'), }, }); ``` diff --git a/packages/@aws-cdk/aws-lambda/README.md b/packages/@aws-cdk/aws-lambda/README.md index 54e7811688134..8b247dd032956 100644 --- a/packages/@aws-cdk/aws-lambda/README.md +++ b/packages/@aws-cdk/aws-lambda/README.md @@ -36,6 +36,9 @@ runtime code. * `lambda.Code.fromAsset(path)` - specify a directory or a .zip file in the local filesystem which will be zipped and uploaded to S3 before deployment. See also [bundling asset code](#bundling-asset-code). + * `lambda.Code.fromDockerBuildAsset(path, options)` - use the result of a Docker + build as code. The runtime code is expected to be located at `/asset` in the + image. The following example shows how to define a Python function and deploy the code from the local directory `my-lambda-handler` to it: @@ -433,8 +436,8 @@ new lambda.Function(this, 'Function', { Runtimes expose a `bundlingDockerImage` property that points to the [AWS SAM](https://github.com/awslabs/aws-sam-cli) build image. -Use `cdk.BundlingDockerImage.fromRegistry(image)` to use an existing image or -`cdk.BundlingDockerImage.fromAsset(path)` to build a specific image: +Use `cdk.DockerImage.fromRegistry(image)` to use an existing image or +`cdk.DockerImage.fromBuild(path)` to build a specific image: ```ts import * as cdk from '@aws-cdk/core'; @@ -442,7 +445,7 @@ import * as cdk from '@aws-cdk/core'; new lambda.Function(this, 'Function', { code: lambda.Code.fromAsset('/path/to/handler', { bundling: { - image: cdk.BundlingDockerImage.fromAsset('/path/to/dir/with/DockerFile', { + image: cdk.DockerImage.fromBuild('/path/to/dir/with/DockerFile', { buildArgs: { ARG1: 'value1', }, diff --git a/packages/@aws-cdk/aws-lambda/lib/code.ts b/packages/@aws-cdk/aws-lambda/lib/code.ts index fef200a9a6c9c..41f94d06dabc4 100644 --- a/packages/@aws-cdk/aws-lambda/lib/code.ts +++ b/packages/@aws-cdk/aws-lambda/lib/code.ts @@ -53,6 +53,19 @@ export abstract class Code { return new AssetCode(path, options); } + /** + * Loads the function code from an asset created by a Docker build. + * + * The asset is expected to be located at `/asset` in the image. + * + * @param path The path to the directory containing the Docker file + * @param options Docker build options + */ + public static fromDockerBuildAsset(path: string, options: cdk.DockerBuildOptions = {}): AssetCode { + const assetPath = cdk.DockerImage.fromBuild(path, options).cp('/asset'); + return new AssetCode(assetPath); + } + /** * DEPRECATED * @deprecated use `fromAsset` diff --git a/packages/@aws-cdk/aws-lambda/test/code.test.ts b/packages/@aws-cdk/aws-lambda/test/code.test.ts index a822ba698697e..0ab84ee5dbdba 100644 --- a/packages/@aws-cdk/aws-lambda/test/code.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/code.test.ts @@ -307,6 +307,29 @@ describe('code', () => { }); }); }); + + describe('lambda.Code.fromDockerBuildAsset', () => { + test('can use the result of a Docker build as an asset', () => { + // given + const stack = new cdk.Stack(); + stack.node.setContext(cxapi.ASSET_RESOURCE_METADATA_ENABLED_CONTEXT, true); + + // when + new lambda.Function(stack, 'Fn', { + code: lambda.Code.fromDockerBuildAsset(path.join(__dirname, 'docker-build-lambda')), + handler: 'index.handler', + runtime: lambda.Runtime.NODEJS_12_X, + }); + + // then + expect(stack).toHaveResource('AWS::Lambda::Function', { + Metadata: { + [cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.38cd320fa97b348accac88e48d9cede4923f7cab270ce794c95a665be83681a8', + [cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY]: 'Code', + }, + }, ResourcePart.CompleteDefinition); + }); + }); }); function defineFunction(code: lambda.Code, runtime: lambda.Runtime = lambda.Runtime.NODEJS_10_X) { diff --git a/packages/@aws-cdk/aws-s3-assets/README.md b/packages/@aws-cdk/aws-s3-assets/README.md index 3d508070d6a50..fbe7441e7347b 100644 --- a/packages/@aws-cdk/aws-s3-assets/README.md +++ b/packages/@aws-cdk/aws-s3-assets/README.md @@ -88,8 +88,8 @@ The following example uses custom asset bundling to convert a markdown file to h [Example of using asset bundling](./test/integ.assets.bundling.lit.ts). -The bundling docker image (`image`) can either come from a registry (`BundlingDockerImage.fromRegistry`) -or it can be built from a `Dockerfile` located inside your project (`BundlingDockerImage.fromAsset`). +The bundling docker image (`image`) can either come from a registry (`DockerImage.fromRegistry`) +or it can be built from a `Dockerfile` located inside your project (`DockerImage.fromBuild`). You can set the `CDK_DOCKER` environment variable in order to provide a custom docker program to execute. This may sometime be needed when building in @@ -114,7 +114,7 @@ new assets.Asset(this, 'BundledAsset', { }, }, // Docker bundling fallback - image: BundlingDockerImage.fromRegistry('alpine'), + image: DockerImage.fromRegistry('alpine'), command: ['bundle'], }, }); diff --git a/packages/@aws-cdk/core/lib/bundling.ts b/packages/@aws-cdk/core/lib/bundling.ts index c9a9c07e77f34..eadc913e380f2 100644 --- a/packages/@aws-cdk/core/lib/bundling.ts +++ b/packages/@aws-cdk/core/lib/bundling.ts @@ -89,6 +89,8 @@ export interface ILocalBundling { /** * A Docker image used for asset bundling + * + * @deprecated use DockerImage */ export class BundlingDockerImage { /** @@ -105,6 +107,8 @@ export class BundlingDockerImage { * * @param path The path to the directory containing the Docker file * @param options Docker build options + * + * @deprecated use DockerImage.fromBuild() */ public static fromAsset(path: string, options: DockerBuildOptions = {}) { const buildArgs = options.buildArgs || {}; @@ -135,7 +139,7 @@ export class BundlingDockerImage { } /** @param image The Docker image */ - private constructor(public readonly image: string, private readonly _imageHash?: string) {} + protected constructor(public readonly image: string, private readonly _imageHash?: string) {} /** * Provides a stable representation of this image for JSON serialization. @@ -174,8 +178,8 @@ export class BundlingDockerImage { /** * Copies a file or directory out of the Docker image to the local filesystem */ - public cp(imagePath: string, outputPath: string) { - const { stdout } = dockerExec(['create', this.image]); + public cp(imagePath: string, outputPath?: string): string { + const { stdout } = dockerExec(['create', this.image], {}); // Empty options to avoid stdout redirect here const match = stdout.toString().match(/([0-9a-f]{16,})/); if (!match) { throw new Error('Failed to extract container ID from Docker create output'); @@ -184,7 +188,9 @@ export class BundlingDockerImage { const containerId = match[1]; const containerPath = `${containerId}:${imagePath}`; try { - dockerExec(['cp', containerPath, outputPath]); + const assetPath = outputPath ?? FileSystem.mkdtemp('cdk-docker-cp-'); + dockerExec(['cp', containerPath, assetPath]); + return assetPath; } catch (err) { throw new Error(`Failed to copy files from ${containerPath} to ${outputPath}: ${err}`); } finally { @@ -193,6 +199,21 @@ export class BundlingDockerImage { } } +/** + * A Docker image + */ +export class DockerImage extends BundlingDockerImage { + /** + * Builds a Docker image + * + * @param path The path to the directory containing the Docker file + * @param options Docker build options + */ + public static fromBuild(path: string, options: DockerBuildOptions = {}) { + return BundlingDockerImage.fromAsset(path, options); + } +} + /** * A Docker volume */ diff --git a/packages/@aws-cdk/core/test/bundling.test.ts b/packages/@aws-cdk/core/test/bundling.test.ts index e2b0d6b43b98b..1b371fb9d51dd 100644 --- a/packages/@aws-cdk/core/test/bundling.test.ts +++ b/packages/@aws-cdk/core/test/bundling.test.ts @@ -3,7 +3,7 @@ import * as crypto from 'crypto'; import * as path from 'path'; import { nodeunitShim, Test } from 'nodeunit-shim'; import * as sinon from 'sinon'; -import { BundlingDockerImage, FileSystem } from '../lib'; +import { BundlingDockerImage, DockerImage, FileSystem } from '../lib'; nodeunitShim({ 'tearDown'(callback: any) { @@ -225,4 +225,25 @@ nodeunitShim({ test.ok(spawnSyncStub.calledWith(sinon.match.any, ['rm', '-v', containerId])); test.done(); }, + + 'cp utility copies to a temp dir of outputPath is omitted'(test: Test) { + // GIVEN + const containerId = '1234567890abcdef1234567890abcdef'; + sinon.stub(child_process, 'spawnSync').returns({ + status: 0, + stderr: Buffer.from('stderr'), + stdout: Buffer.from(`${containerId}\n`), + pid: 123, + output: ['stdout', 'stderr'], + signal: null, + }); + + // WHEN + const tempPath = DockerImage.fromRegistry('alpine').cp('/foo/bar'); + + // THEN + test.ok(/cdk-docker-cp-/.test(tempPath)); + + test.done(); + }, }); From fc42705700f94af1a3e360511a50939df3a02416 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Tue, 29 Dec 2020 13:31:34 +0100 Subject: [PATCH 2/9] jsdoc --- packages/@aws-cdk/core/lib/bundling.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/core/lib/bundling.ts b/packages/@aws-cdk/core/lib/bundling.ts index eadc913e380f2..ffdce86202d22 100644 --- a/packages/@aws-cdk/core/lib/bundling.ts +++ b/packages/@aws-cdk/core/lib/bundling.ts @@ -176,7 +176,13 @@ export class BundlingDockerImage { } /** - * Copies a file or directory out of the Docker image to the local filesystem + * Copies a file or directory out of the Docker image to the local filesystem. + * + * If `outputPath` is omitted the destination path is a temporary directory. + * + * @param imagePath the path in the Docker image + * @param outputPath the destination path for the copy operation + * @returns the destination path */ public cp(imagePath: string, outputPath?: string): string { const { stdout } = dockerExec(['create', this.image], {}); // Empty options to avoid stdout redirect here @@ -188,8 +194,8 @@ export class BundlingDockerImage { const containerId = match[1]; const containerPath = `${containerId}:${imagePath}`; try { - const assetPath = outputPath ?? FileSystem.mkdtemp('cdk-docker-cp-'); - dockerExec(['cp', containerPath, assetPath]); + const destPath = outputPath ?? FileSystem.mkdtemp('cdk-docker-cp-'); + dockerExec(['cp', containerPath, destPath]); return assetPath; } catch (err) { throw new Error(`Failed to copy files from ${containerPath} to ${outputPath}: ${err}`); From 71d3b3a25562360bb03a941cb9d2d5aeb1193007 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Tue, 29 Dec 2020 17:23:55 +0100 Subject: [PATCH 3/9] destPath --- packages/@aws-cdk/core/lib/bundling.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/core/lib/bundling.ts b/packages/@aws-cdk/core/lib/bundling.ts index ffdce86202d22..b8d5a2827acdf 100644 --- a/packages/@aws-cdk/core/lib/bundling.ts +++ b/packages/@aws-cdk/core/lib/bundling.ts @@ -196,7 +196,7 @@ export class BundlingDockerImage { try { const destPath = outputPath ?? FileSystem.mkdtemp('cdk-docker-cp-'); dockerExec(['cp', containerPath, destPath]); - return assetPath; + return destPath; } catch (err) { throw new Error(`Failed to copy files from ${containerPath} to ${outputPath}: ${err}`); } finally { From f8aaeb8b2c96b201f78a7cbc8d908815635759ef Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Tue, 29 Dec 2020 17:29:38 +0100 Subject: [PATCH 4/9] error message --- packages/@aws-cdk/core/lib/bundling.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/core/lib/bundling.ts b/packages/@aws-cdk/core/lib/bundling.ts index b8d5a2827acdf..7c5d6804c19f3 100644 --- a/packages/@aws-cdk/core/lib/bundling.ts +++ b/packages/@aws-cdk/core/lib/bundling.ts @@ -193,12 +193,12 @@ export class BundlingDockerImage { const containerId = match[1]; const containerPath = `${containerId}:${imagePath}`; + const destPath = outputPath ?? FileSystem.mkdtemp('cdk-docker-cp-'); try { - const destPath = outputPath ?? FileSystem.mkdtemp('cdk-docker-cp-'); dockerExec(['cp', containerPath, destPath]); return destPath; } catch (err) { - throw new Error(`Failed to copy files from ${containerPath} to ${outputPath}: ${err}`); + throw new Error(`Failed to copy files from ${containerPath} to ${destPath}: ${err}`); } finally { dockerExec(['rm', '-v', containerId]); } From acb64775f5bad9c04e6f2d22c1925b055cd196f7 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Tue, 29 Dec 2020 17:30:05 +0100 Subject: [PATCH 5/9] lambda test --- .../@aws-cdk/aws-lambda/test/docker-build-lambda/Dockerfile | 3 +++ .../@aws-cdk/aws-lambda/test/docker-build-lambda/index.ts | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 packages/@aws-cdk/aws-lambda/test/docker-build-lambda/Dockerfile create mode 100644 packages/@aws-cdk/aws-lambda/test/docker-build-lambda/index.ts diff --git a/packages/@aws-cdk/aws-lambda/test/docker-build-lambda/Dockerfile b/packages/@aws-cdk/aws-lambda/test/docker-build-lambda/Dockerfile new file mode 100644 index 0000000000000..4643fde141850 --- /dev/null +++ b/packages/@aws-cdk/aws-lambda/test/docker-build-lambda/Dockerfile @@ -0,0 +1,3 @@ +FROM public.ecr.aws/amazonlinux/amazonlinux:latest + +COPY index.js /asset diff --git a/packages/@aws-cdk/aws-lambda/test/docker-build-lambda/index.ts b/packages/@aws-cdk/aws-lambda/test/docker-build-lambda/index.ts new file mode 100644 index 0000000000000..cc867895b4efc --- /dev/null +++ b/packages/@aws-cdk/aws-lambda/test/docker-build-lambda/index.ts @@ -0,0 +1,5 @@ +/* eslint-disable no-console */ +export async function handler(event: any) { + console.log('Event: %j', event); + return event; +} From 4f4c518438771c432860ce7c011a4b7c10ce7701 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Wed, 30 Dec 2020 10:52:29 +0100 Subject: [PATCH 6/9] nodejs bundling test --- packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts b/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts index c665b862ad93f..130b57ab582c9 100644 --- a/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts +++ b/packages/@aws-cdk/aws-lambda-nodejs/test/bundling.test.ts @@ -20,7 +20,7 @@ beforeEach(() => { getEsBuildVersionMock.mockReturnValue('0.8.8'); fromAssetMock.mockReturnValue({ image: 'built-image', - cp: () => {}, + cp: () => 'dest-path', run: () => {}, toJSON: () => 'built-image', }); From f30c1744b3be8181c06f27d3cca401b2dd68f5d9 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Thu, 18 Feb 2021 08:45:15 +0100 Subject: [PATCH 7/9] DockerBuildAssetOptions --- packages/@aws-cdk/aws-lambda/README.md | 4 ++-- packages/@aws-cdk/aws-lambda/lib/code.ts | 30 +++++++++++++++++++++--- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda/README.md b/packages/@aws-cdk/aws-lambda/README.md index bb9840a6ce475..e2c5e338453db 100644 --- a/packages/@aws-cdk/aws-lambda/README.md +++ b/packages/@aws-cdk/aws-lambda/README.md @@ -38,7 +38,7 @@ runtime code. [bundling asset code](#bundling-asset-code). * `lambda.Code.fromDockerBuildAsset(path, options)` - use the result of a Docker build as code. The runtime code is expected to be located at `/asset` in the - image. + image and will be zipped and uploaded to S3 as an asset. The following example shows how to define a Python function and deploy the code from the local directory `my-lambda-handler` to it: @@ -453,7 +453,7 @@ new lambda.Function(this, 'Function', { bundling: { image: lambda.Runtime.PYTHON_3_6.bundlingDockerImage, command: [ - 'bash', '-c', + 'bash', '-c', 'pip install -r requirements.txt -t /asset-output && cp -au . /asset-output' ], }, diff --git a/packages/@aws-cdk/aws-lambda/lib/code.ts b/packages/@aws-cdk/aws-lambda/lib/code.ts index 79e042a16f751..010cd31c40397 100644 --- a/packages/@aws-cdk/aws-lambda/lib/code.ts +++ b/packages/@aws-cdk/aws-lambda/lib/code.ts @@ -60,13 +60,16 @@ export abstract class Code { /** * Loads the function code from an asset created by a Docker build. * - * The asset is expected to be located at `/asset` in the image. + * By defaut, the asset is expected to be located at `/asset` in the + * image. * * @param path The path to the directory containing the Docker file * @param options Docker build options */ - public static fromDockerBuildAsset(path: string, options: cdk.DockerBuildOptions = {}): AssetCode { - const assetPath = cdk.DockerImage.fromBuild(path, options).cp('/asset'); + public static fromDockerBuildAsset(path: string, options: DockerBuildAssetOptions = {}): AssetCode { + const assetPath = cdk.DockerImage + .fromBuild(path, options) + .cp(options.imagePath ?? '/asset', options.outputPath); return new AssetCode(assetPath); } @@ -501,3 +504,24 @@ export class AssetImageCode extends Code { }; } } + +/** + * Options when creating an asset from a Docker build. + */ +export interface DockerBuildAssetOptions extends cdk.DockerBuildOptions { + /** + * The path in the Docker image where the asset is located after the build + * operation. + * + * @default /asset + */ + readonly imagePath?: string; + + /** + * The path on the local filesystem where the asset will be copied + * using `docker cp`. + * + * @default - a unique temporary directory in the system temp directory + */ + readonly outputPath?: string; +} From 7ccc3fce8089958a81400609f4e8a6c3d0c47f96 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Thu, 18 Feb 2021 08:58:09 +0100 Subject: [PATCH 8/9] s3-assets README --- packages/@aws-cdk/aws-s3-assets/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-s3-assets/README.md b/packages/@aws-cdk/aws-s3-assets/README.md index 4b499f157b47a..7a751410a2b22 100644 --- a/packages/@aws-cdk/aws-s3-assets/README.md +++ b/packages/@aws-cdk/aws-s3-assets/README.md @@ -135,7 +135,7 @@ Use `BundlingOutput.NOT_ARCHIVED` if the bundling output must always be zipped: const asset = new assets.Asset(this, 'BundledAsset', { path: '/path/to/asset', bundling: { - image: BundlingDockerImage.fromRegistry('alpine'), + image: DockerImage.fromRegistry('alpine'), command: ['command-that-produces-an-archive.sh'], outputType: BundlingOutput.NOT_ARCHIVED, // Bundling output will be zipped even though it produces a single archive file. }, From 8922fafeb40bd13132c52c2eb61f7b4e0865b597 Mon Sep 17 00:00:00 2001 From: Jonathan Goldwasser Date: Thu, 18 Feb 2021 11:32:10 +0100 Subject: [PATCH 9/9] fromDockerBuild --- packages/@aws-cdk/aws-lambda/README.md | 2 +- packages/@aws-cdk/aws-lambda/lib/code.ts | 2 +- packages/@aws-cdk/aws-lambda/test/code.test.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/@aws-cdk/aws-lambda/README.md b/packages/@aws-cdk/aws-lambda/README.md index e2c5e338453db..1f4ee7e5aaa46 100644 --- a/packages/@aws-cdk/aws-lambda/README.md +++ b/packages/@aws-cdk/aws-lambda/README.md @@ -36,7 +36,7 @@ runtime code. * `lambda.Code.fromAsset(path)` - specify a directory or a .zip file in the local filesystem which will be zipped and uploaded to S3 before deployment. See also [bundling asset code](#bundling-asset-code). - * `lambda.Code.fromDockerBuildAsset(path, options)` - use the result of a Docker + * `lambda.Code.fromDockerBuild(path, options)` - use the result of a Docker build as code. The runtime code is expected to be located at `/asset` in the image and will be zipped and uploaded to S3 as an asset. diff --git a/packages/@aws-cdk/aws-lambda/lib/code.ts b/packages/@aws-cdk/aws-lambda/lib/code.ts index 010cd31c40397..b4f41b2804257 100644 --- a/packages/@aws-cdk/aws-lambda/lib/code.ts +++ b/packages/@aws-cdk/aws-lambda/lib/code.ts @@ -66,7 +66,7 @@ export abstract class Code { * @param path The path to the directory containing the Docker file * @param options Docker build options */ - public static fromDockerBuildAsset(path: string, options: DockerBuildAssetOptions = {}): AssetCode { + public static fromDockerBuild(path: string, options: DockerBuildAssetOptions = {}): AssetCode { const assetPath = cdk.DockerImage .fromBuild(path, options) .cp(options.imagePath ?? '/asset', options.outputPath); diff --git a/packages/@aws-cdk/aws-lambda/test/code.test.ts b/packages/@aws-cdk/aws-lambda/test/code.test.ts index b310fbc9021d6..7de7998b19c85 100644 --- a/packages/@aws-cdk/aws-lambda/test/code.test.ts +++ b/packages/@aws-cdk/aws-lambda/test/code.test.ts @@ -328,7 +328,7 @@ describe('code', () => { }); }); - describe('lambda.Code.fromDockerBuildAsset', () => { + describe('lambda.Code.fromDockerBuild', () => { test('can use the result of a Docker build as an asset', () => { // given const stack = new cdk.Stack(); @@ -336,7 +336,7 @@ describe('code', () => { // when new lambda.Function(stack, 'Fn', { - code: lambda.Code.fromDockerBuildAsset(path.join(__dirname, 'docker-build-lambda')), + code: lambda.Code.fromDockerBuild(path.join(__dirname, 'docker-build-lambda')), handler: 'index.handler', runtime: lambda.Runtime.NODEJS_12_X, });