question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-lambda): fromDockerBuild output is located incorrectly

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jogoldcommented, Mar 9, 2021

@phuctm97 are you taking this? I see a commit on your fork that references this issue.

I was thinking that something like this would do it:

public static fromDockerBuild(path: string, options: DockerBuildAssetOptions = {}): AssetCode {
  const imagePath = options.imagePath ?? '/asset';
  const assetPath = cdk.DockerImage
    .fromBuild(path, options)
    // ensure imagePath ends with /. to copy the **content** at this path
    .cp(imagePath.replace(/(\/|\/\.)?$/, '/.'), options.outputPath);
  return new AssetCode(assetPath);
}

I would personally not change the cp() method in core, I think it must remain general purpose.

(cc @eladb)

0reactions
github-actions[bot]commented, Mar 11, 2021

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshoot container image issues in Lambda
Verify that the ENTRYPOINT to your container image includes the absolute path as the location. Also verify that the image does not contain...
Read more >
Creating Lambda container images - AWS Documentation
Create a container image for a Lambda function by using an AWS provided base image or an alternative base image.
Read more >
Troubleshoot deployment issues in Lambda
This issue can occur when you specify an Amazon S3 object in a call to UpdateFunctionCode, or use the package and deploy commands...
Read more >
Testing Lambda container images locally - AWS Documentation
Test the container image for your AWS Lambda function locally using the runtime interface ... Build your image locally using the docker build...
Read more >
Troubleshooting errors with Docker commands when using ...
You can work around this bug by removing the https:// scheme from the registry argument in the Docker login command that is output...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found