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-nodejs] Bundling a lambda_nodejs.NodejsFunction fails after upgrading to 1.58.0 #9673

Closed
markusl opened this issue Aug 13, 2020 · 19 comments
Assignees
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/small Small work item – less than a day of effort needs-triage This issue or PR still needs to be triaged. p1

Comments

@markusl
Copy link
Contributor

markusl commented Aug 13, 2020

It seems that there might be something wrong with generating 'asset-output/index.js'.

This is the log I get from 'yarn build':

Run yarn build
yarn run v1.22.4
$ yarn test && yarn compile && yarn run package
$ yarn eslint && rm -fr lib/ && jest --passWithNoTests --updateSnapshot
$ eslint . --ext .ts
[eslint-import-resolver-typescript]: option `directory` is deprecated, please use `project` instead
Bundling asset testing-stack/ecr-scan-result-handler/handler/Code/Stage...
🚨 Build failed.
Error: Entry /asset-input/cdk-ecr-image-scan-handler/lambda-handler/handler.ts does not exist
Error: Entry /asset-input/cdk-ecr-image-scan-handler/lambda-handler/handler.ts does not exist
    at EntryResolver.resolveEntry (/node_modules/@parcel/core/lib/EntryResolver.js:44:13)
[Error: Invalid argument]
FAIL test/index.test.ts (127.674 s)
  ✕ Create EcrImageScanResultHandler (124115 ms)

  ● Create EcrImageScanResultHandler

    Failed to bundle asset testing-stack/ecr-scan-result-handler/handler/Code/Stage: Error: docker exited with status 1

I did not find very comprehensive examples about how to create this kind of reusable module with Typescript code bundled in an AWS Lambda. Please advise if there is a configuration error in the project.

Reproduction Steps

See the code at https://github.com/markusl/cdk-ecr-image-scan-handler and run 'yarn build'

What did you expect to happen?

The code should be bundled as a JSII template.

What actually happened?

I received the error.

Environment

  • CLI Version : 1.58.0
  • Framework Version: 1.58.0
  • Node.js Version: v12.14.1
  • OS : Mac
  • Language (Version): TypeScript

Other


This is 🐛 Bug Report

@markusl markusl added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 13, 2020
@SomayaB SomayaB changed the title [lambda_nodejs] Bundling a lambda_nodejs.NodejsFunction fails after upgrading to 1.58.0 [lambda-nodejs] Bundling a lambda_nodejs.NodejsFunction fails after upgrading to 1.58.0 Aug 13, 2020
@jogold
Copy link
Contributor

jogold commented Aug 14, 2020

Hi @markusl

I pulled your repo and ran yarn && yarn build successfully...

Something with your Docker installation? Can you give more details about your environment?

@markusl
Copy link
Contributor Author

markusl commented Aug 14, 2020

@jogold well, I got the same result after doing a fresh clone and running the commands. However, you can see the issue in Github workflows https://github.com/markusl/cdk-ecr-image-scan-handler/runs/984246568
Please let me know if you have any ideas about why it might fail.

@jogold
Copy link
Contributor

jogold commented Aug 14, 2020

Please let me know if you have any ideas about why it might fail.

Is Docker available in your Github Action?

If not, "local bundling" is coming #9632 soon...

@markusl
Copy link
Contributor Author

markusl commented Aug 14, 2020

@jogold I'm not sure what do you mean? The Github workflow is generated by the 'projen' tool and should likely include what's needed.

Something has changed between 1.57.0 and 1.58.0 since I'm also getting the same error now locally after running:

  • npx projen && yarn install
  • yarn build

@jogold
Copy link
Contributor

jogold commented Aug 14, 2020

OK, projen makes your package.json readonly so the bundler cannot modify it to configure bundling... is this the error you are getting? EACCES on your package.json?

Can you try npx projen && chmod 755 package.json && yarn install && yarn build?

(cc @eladb)

@markusl
Copy link
Contributor Author

markusl commented Aug 14, 2020

@jogold right, that seems to solve the local build for that configuration. However, I'm trying to figure out how the project configuration should be done to avoid this: https://github.com/markusl/cdk-ecr-image-scan-handler/runs/984349252

🚨 Build failed.
Error: Entry /asset-input/cdk-ecr-image-scan-handler/lambda-handler/handler.ts does not exist
Error: Entry /asset-input/cdk-ecr-image-scan-handler/lambda-handler/handler.ts does not exist

Do you have a reference setup for how to provide directory layout, projectRoot and entry for lambda_nodejs.NodejsFunction?

@thantos
Copy link
Contributor

thantos commented Aug 14, 2020

Cut a similar issue (#9709). I think your issue can be solved, or at least changed to a new error, by clearing the output cache. Not sure which one, so all to be safe: .parcel-cache, .cdk.staging, cdk.out.

@thantos
Copy link
Contributor

thantos commented Aug 15, 2020

Also by cdk-lambda and targets from your package.json.

@eladb eladb added effort/small Small work item – less than a day of effort p1 labels Aug 17, 2020
@jogold
Copy link
Contributor

jogold commented Aug 17, 2020

@markusl is this still an issue? were you able to build? does it only fail in your GitHub Action?

@markusl
Copy link
Contributor Author

markusl commented Aug 18, 2020

@jogold Yes, there are still several issues related to publishing a JSII construct that includes a NodejsFunction that contains single or multiple files that are packaged.

  1. I'd like to understand why the build fails under Github actions: Error: Entry /asset-input/src/index.handler.ts does not exist

  2. I do still get an error EACCES: permission denied, open 'cdk-ecr-image-scan-handler/package.json' after running npx projen && yarn install && yarn build, as discussed earlier.

Please let me know if I'm trying to do something that the construct is not designed to do. It might just be easier if you provided a reference implementation that users could fork to start working on their custom constructs.

@aletheia
Copy link

Hit the same issue when starting a fresh new project to demonstrate this bug https://github.com/aws/aws-cdk/issues/9812.

The project is here:
https://github.com/aletheia/test-aws-cdk-nodejs

As you can see is very simple, but when running

npm run deploy

It produces this output:

Bundling asset TestNodejsfunctionWinstonStack/test-function/Code/Stage...
Building index.ts...
Building index.ts...
Bundling...
✨ Built in 16.21s

../../../../asset-output/index.js    421.57 KB    377ms
mv: ‘/asset-output/index.js’ and ‘/asset-output/index.js’ are the same file
Failed to bundle asset TestNodejsfunctionWinstonStack/test-function/Code/Stage: Error: docker exited with status 1
Subprocess exited with error 1
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test-nodejsfunction-winston@0.1.0 deploy: `npm run compile && cdk deploy --require-approval never`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the test-nodejsfunction-winston@0.1.0 deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

With no further information.

@aletheia
Copy link

Hit the same issue when starting a fresh new project to demonstrate this bug https://github.com/aws/aws->
[...]
With no further information.

I can confirm that with CDK v. 1.57.0 it works like a charm

@thantos
Copy link
Contributor

thantos commented Aug 19, 2020

Resolved here: #9709. In 58->59 entry: [anything]/index.[ts|js] will result in the error you are getting.

@aletheia
Copy link

Resolved here: #9709. In 58->59 entry: [anything]/index.[ts|js] will result in the error you are getting.

The problem happened yesterday, after upgrading from 1.57.0 to 1.59.0.
Tested right now with 1.59.0 it's still not working.

@jogold
Copy link
Contributor

jogold commented Aug 19, 2020

The fix for index.js is not included in 1.59.0, will be in the next release

@eladb
Copy link
Contributor

eladb commented Aug 19, 2020

Closing for now. Reopen if 1.60.0 does not solve this

@pgarbe
Copy link
Contributor

pgarbe commented Aug 30, 2020

Please, re-open as this error still exists with CDK v1.61.1. It works locally, but not in GitHub Actions (see https://github.com/pgarbe/cdk-ecr-sync/runs/1048483828?check_suite_focus=true#step:9:10)

@jogold
Copy link
Contributor

jogold commented Aug 31, 2020

@pgarbe in a GitHub Action you should try with Local bundling.

@pgarbe
Copy link
Contributor

pgarbe commented Aug 31, 2020

That worked. Thanks @jogold

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-lambda-nodejs bug This issue is a bug. effort/small Small work item – less than a day of effort needs-triage This issue or PR still needs to be triaged. p1
Projects
None yet
Development

No branches or pull requests

6 participants