Aws-cdk: [lambda-nodejs] Bundling a lambda_nodejs.NodejsFunction fails after upgrading to 1.58.0

Created on 13 Aug 2020  ·  19Comments  ·  Source: aws/aws-cdk

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: Bug Report

@aws-cdaws-lambda-nodejs bug efforsmall needs-triage p1

All 19 comments

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?

@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.

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

@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

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)

@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?

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.

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

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

@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.

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! [email protected] deploy: `npm run compile && cdk deploy --require-approval never`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] deploy script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

With no further information.

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

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

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.

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

Closing for now. Reopen if 1.60.0 does not solve this

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)

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

That worked. Thanks @jogold

Was this page helpful?
0 / 5 - 0 ratings