Skip to content

Commit c95cc09

Browse files
committed
fix(lambda): fromDockerBuild output is located under /asset
Ensure `imagePath` ends with `/.` so that the content at that location is copied. See https://docs.docker.com/engine/reference/commandline/cp/ Closes #13439
1 parent e9cd1e8 commit c95cc09

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,11 @@ export abstract class Code {
6767
* @param options Docker build options
6868
*/
6969
public static fromDockerBuild(path: string, options: DockerBuildAssetOptions = {}): AssetCode {
70+
const imagePath = options.imagePath ?? '/asset';
7071
const assetPath = cdk.DockerImage
7172
.fromBuild(path, options)
72-
.cp(options.imagePath ?? '/asset', options.outputPath);
73+
// ensure imagePath ends with /. to copy the **content** at this path
74+
.cp(imagePath.replace(/(\/|\/\.)?$/, '/.'), options.outputPath);
7375
return new AssetCode(assetPath);
7476
}
7577

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ describe('code', () => {
346346
// then
347347
expect(stack).toHaveResource('AWS::Lambda::Function', {
348348
Metadata: {
349-
[cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.38cd320fa97b348accac88e48d9cede4923f7cab270ce794c95a665be83681a8',
349+
[cxapi.ASSET_RESOURCE_METADATA_PATH_KEY]: 'asset.20276d7803bfd6f4a2a5dc48692eb300d676b2a0dfdd4bda78c56c7c2c461515',
350350
[cxapi.ASSET_RESOURCE_METADATA_PROPERTY_KEY]: 'Code',
351351
},
352352
}, ResourcePart.CompleteDefinition);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
FROM public.ecr.aws/amazonlinux/amazonlinux:latest
22

3-
COPY index.js /asset
3+
COPY index.js /asset/

0 commit comments

Comments
 (0)