Skip to content

(aws-lambda): fromDockerBuild output is located incorrectly #13439

@phuctm97

Description

@phuctm97

In v1.92.0, when fromDockerBuild is used, it is expected that contents /asset is copied, but instead the whole /asset is copied to output path, this makes Lambda handler reference index.handler failed, it has to be asset/index.handler.

Reproduction Steps

Create a index.js.

exports.handler = () => {
  console.info("Test");
}

A Dockerfile:

FROM amazon/aws-sam-cli-build-image-nodejs14.x
COPY index.js /asset/

Use lambda.Code.fromDockerBuild:

export class ExampleStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new lambda.Function(this, "ExampleFunction", {
      runtime: lambda.Runtime.NODEJS_14_X,
      handler: "index.handler",
      code: lambda.Code.fromDockerBuild(ROOT_DIR),
    });
  }
}

What did you expect to happen?

The Lamda code contains only index.js.

What actually happened?

The Lambda code contains asset/index.js.

Environment

  • CDK CLI Version : 1.92.0
  • Framework Version: 1.92.0
  • Node.js Version: 14
  • OS : macOS Catalina
  • Language (Version): TypeScript 4.2.3

Other

This is caused by expected behavior of docker cp.

Suggestion: automatically append /. to imagePath if it doesn't.


This is 🐛 Bug Report

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-lambdaRelated to AWS LambdabugThis issue is a bug.effort/mediumMedium work item – several days of effortp2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions