Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lambda] lambda.Code.FromAsset Golang bundling permission denied at execution #10776

Closed
strongishllama opened this issue Oct 7, 2020 · 14 comments · Fixed by #13076
Closed

[lambda] lambda.Code.FromAsset Golang bundling permission denied at execution #10776

strongishllama opened this issue Oct 7, 2020 · 14 comments · Fixed by #13076
Assignees
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package bug This issue is a bug. effort/small Small work item – less than a day of effort os/windows Related specifically to Windows behavior p1

Comments

@strongishllama
Copy link

strongishllama commented Oct 7, 2020

❓ General Issue

The Question

I've been trying to deploy a Lambda function written in Go using lambda.Code.fromAsset and the experimental BundlingOptions inside the AssetOptions parameter. I'm able to deploy the stack with no issues at all but I get a permission denied error on the Lambda when trying to execute it.

{
  "errorMessage": "fork/exec /var/task/hello-world: permission denied",
  "errorType": "PathError"
}

When I download the zipped source from S3 to look at the binaries permissions it should be able to execute it.

total 13808
drwxrwxrwx 1 strongishllama strongishllama     512 Oct  8 10:31 ./
drwxrwxrwx 1 strongishllama strongishllama     512 Oct  8 10:23 ../
-rwxrwxrwx 1 strongishllama strongishllama 9291301 Oct  8 10:23 hello-world*

Here's the Lambda function snippet from CDK.

    const handler = new lambda.Function(this, `HelloWorld-${props.suffix}`, {
      runtime: lambda.Runtime.GO_1_X,
      code: lambda.Code.fromAsset("assets/lambdas/hello-world", {
        bundling: {
          image: lambda.Runtime.GO_1_X.bundlingDockerImage,
          command: [
            "bash", "-c", [
              "go build -o /asset-output/hello-world*.go",
              "chmod +x /asset-output/hello-world"
            ].join(" && ")
          ],
          user: "root"
        }
      }),
      handler: "hello-world"
    });

I've also tried building and zipping locally then uploading it manually to the existing Lambda function and it works as expected.

Any help would be appreciated. Thanks!

Environment

  • CDK CLI Version: 1.67.0 (build 2b4dd71)
  • Module Version: 1.67.0
  • Node.js Version: v14.10.1
  • OS: Windows 10 Home
  • Language (Version): TypeScript (4.0.3)
@strongishllama strongishllama added guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels Oct 7, 2020
@github-actions github-actions bot added the @aws-cdk/aws-lambda Related to AWS Lambda label Oct 7, 2020
@strongishllama
Copy link
Author

I just tried this on my Ubuntu machine and it works fine, the environment is as follows.

  • CDK CLI Version: 1.67.0 (build 2b4dd71)
  • Module Version: 1.67.0
  • Node.js Version: v10.19.0
  • OS: Ubuntu 20.04.1 LTS
  • Language (Version): TypeScript (3.9.7)

@NGL321 NGL321 added bug This issue is a bug. os/windows Related specifically to Windows behavior and removed guidance Question that needs advice or information. needs-triage This issue or PR still needs to be triaged. labels Oct 30, 2020
@NGL321
Copy link
Contributor

NGL321 commented Oct 30, 2020

Hi @strongishllama!

Unfortunately I WAS able to reproduce this on Windows and had no issues on OSX, so I think this is likely a bug with the way asset bundling works on Windows. I have changed the labels so that it gets the attention of the relevant dev.

Are you able to run your builds on Ubuntu as mentioned above while this is pending? If not, the best other workaround would be to create a small secondary pipeline stack in CodePipeline to run the deployment from a Codebuild unix environment.

Let me know if that workaround works for you!

😸 😷

@strongishllama
Copy link
Author

strongishllama commented Oct 30, 2020

My primary development device is Ubuntu so all good, but I'll keep that workaround in mind. Thanks!

@pfried
Copy link

pfried commented Nov 2, 2020

Related #7749

The issue ( most likely only on windows) is that files which are bundled will loose their permissions (like beeing executable). As long as seen from inside the container the permissions are correctly set within the asset-output directory.

Inside the container:
image

After running the cdk bundling the permissions are gone:

Outside the container:
image

It seems to me that the files are actually "recreated" somehow since the seem to have a default mask applied to them. The permissions issue is already present on the output folder, hence it has nothing to do with the zip file creation.

As docker volumes are tricky I suspect an issue with using volumes or the fs operations.

Note: I do use Docker engine v19.03.13 with WSL 2 on a Windows 10 AMD64 host

@strongishllama what is your windows setup?

@nija-at nija-at added @aws-cdk/assets Related to the @aws-cdk/assets package and removed @aws-cdk/aws-lambda Related to AWS Lambda labels Nov 2, 2020
@nija-at nija-at assigned eladb and unassigned nija-at Nov 2, 2020
@pfried
Copy link

pfried commented Nov 4, 2020

Something I noticed: The permissions in Windows are different from the ones seen from inside the docker container. (Most likely due to filesystem differences), propably the permissions simply get lost when moving the file from the container to windows. One idea could be to require the user to zip inside the docker container (thats what I now do manually as a workaround)

@pfried
Copy link

pfried commented Dec 9, 2020

@eladb Since you are assigned to this, would it be possible to add an option like outputFile where it would skip the archiving and just use the given output file if it exists? This would make it the users responsibility to provide the ready packaged zip file.

I guess this packaging will never work properly on windows since it will loose the permissions set inside the container.

Besides that there should be a warning at https://docs.aws.amazon.com/cdk/api/latest/docs/aws-s3-assets-readme.html#asset-bundling that bundling on windows might fail (if the file needs e.g. executable permissions).

@eladb
Copy link
Contributor

eladb commented Dec 9, 2020

@pfried sounds like a good direction. @jogold what do you think?

@jogold
Copy link
Contributor

jogold commented Dec 10, 2020

@pfried sounds like a good direction. @jogold what do you think?

@eladb You still don't want to do this automagically if the content in /asset-output is a single archive file?

@pfried
Copy link

pfried commented Dec 10, 2020 via email

@pfried
Copy link

pfried commented Feb 3, 2021

I would like to get back to this, I would be fine with both approaches

@eladb
Copy link
Contributor

eladb commented Feb 15, 2021

@jogold I am okay with doing this automatically if /asset-output includes a single .zip file, but let's add an option to disable this behavior (in case for some odd reason users want to create a bundle that contains a single zip file inside the bundle).

@eladb eladb added effort/small Small work item – less than a day of effort p1 labels Feb 15, 2021
@jogold
Copy link
Contributor

jogold commented Feb 16, 2021

@jogold I am okay with doing this automatically if /asset-output includes a single .zip file, but let's add an option to disable this behavior (in case for some odd reason users want to create a bundle that contains a single zip file inside the bundle).

@eladb started the work in #13076, how would you call this option? alwaysArchive which defaults to false?

@eladb
Copy link
Contributor

eladb commented Feb 16, 2021

@eladb started the work in #13076, how would you call this option? alwaysArchive which defaults to false?

I'd probably go with an enum with three options:

  1. Always zip
  2. Never zip (fail if the output directory does not contain a single zip file)
  3. Auto

It sure about the names...

@mergify mergify bot closed this as completed in #13076 Feb 17, 2021
mergify bot pushed a commit that referenced this issue Feb 17, 2021
If the bundling output contains a single archive file (zip or jar), upload it
as-is to S3 without zipping it.

Allow to customize this behavior with `bundling.packaging`:
* `ALWAYS_ZIP`: The bundling output will always be zipped and uploaded to S3.
* `NEVER_ZIP`: The bundling output will not be zipped. Bundling will fail if
  the bundling output doesn't contain a single file.
* `AUTO`: If the bundling output contains a single archive file (zip or jar) it
  will not be zipped. Otherwise it will be zipped.

Closes #10776 
Closes #12651

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@github-actions
Copy link

⚠️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.

NovakGu pushed a commit to NovakGu/aws-cdk that referenced this issue Feb 18, 2021
If the bundling output contains a single archive file (zip or jar), upload it
as-is to S3 without zipping it.

Allow to customize this behavior with `bundling.packaging`:
* `ALWAYS_ZIP`: The bundling output will always be zipped and uploaded to S3.
* `NEVER_ZIP`: The bundling output will not be zipped. Bundling will fail if
  the bundling output doesn't contain a single file.
* `AUTO`: If the bundling output contains a single archive file (zip or jar) it
  will not be zipped. Otherwise it will be zipped.

Closes aws#10776 
Closes aws#12651

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
eladb pushed a commit that referenced this issue Feb 22, 2021
If the bundling output contains a single archive file (zip or jar), upload it
as-is to S3 without zipping it.

Allow to customize this behavior with `bundling.packaging`:
* `ALWAYS_ZIP`: The bundling output will always be zipped and uploaded to S3.
* `NEVER_ZIP`: The bundling output will not be zipped. Bundling will fail if
  the bundling output doesn't contain a single file.
* `AUTO`: If the bundling output contains a single archive file (zip or jar) it
  will not be zipped. Otherwise it will be zipped.

Closes #10776 
Closes #12651

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/assets Related to the @aws-cdk/assets package bug This issue is a bug. effort/small Small work item – less than a day of effort os/windows Related specifically to Windows behavior p1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants