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-cdk/aws-lambda-nodejs doesn't give useful error messages when builds fail.

See original GitHub issue

We’re looking at switching over from Serverless to CDK for deploying our lambdas to minimise size. One of the things that Serverless does that I don’t know how to do cleanly in CDK is excluding devDependencies from the final built package that gets zipped / uploaded.

How do I go about configuring this behaviour in CDK?


This is a 📕 documentation issue

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:20 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
thekevinbrowncommented, Feb 14, 2020

@jogold I went ahead and ran npm i -g parcel-bundler to work around that error.

Now I get:

[project directory]/backend/packages/infrastructure/node_modules/@aws-cdk/aws-lambda-nodejs/lib/build.ts:85
    throw new Error(`Failed to build file at ${options.entry}: ${err}`);
          ^
Error: Failed to build file at [project directory]/backend/packages/consumer-api/src/index.ts: Error
    at Object.build ([project directory]/backend/packages/infrastructure/node_modules/@aws-cdk/aws-lambda-nodejs/lib/build.ts:85:11)
    at new NodejsFunction ([project directory]/backend/packages/infrastructure/node_modules/@aws-cdk/aws-lambda-nodejs/lib/function.ts:89:5)
    at Object.exports.attach ([project directory]/backend/packages/infrastructure/src/consumer-api/v1/index.ts:31:22)
    at Object.exports.attach ([project directory]/backend/packages/infrastructure/src/consumer-api/index.ts:17:5)
    at new ApiService ([project directory]/backend/packages/infrastructure/src/index.ts:29:15)
    at Object.<anonymous> ([project directory]/backend/packages/infrastructure/src/index.ts:36:1)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Module.m._compile ([project directory]/backend/packages/infrastructure/node_modules/ts-node/src/index.ts:814:23)
    at Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Object.require.extensions.(anonymous function) [as .ts] ([project directory]/backend/packages/infrastructure/node_modules/ts-node/src/index.ts:817:12)

Not sure what to do to figure out what the Error actually is.

1reaction
jogoldcommented, Mar 10, 2020

a) new lambdaNodejs.NodejsFunction by default builds the handler code next to the source code, not in ./.build as your command implies

Yes I know, the point was to see if this is a parcel error and what kind of error. In this case the out-dir doesn’t matter.

deleting any build files, then modifying your command’s out-dir to parcel build src/restart-service/index.ts --out-dir src/restart-service/.build --out-file index.js --global handler --target node --bundle-node-modules --log-level 2 --no-minify, THEN runnning the tests fails

The lambdaNodejs.NodejsFunction builds in a subfolder of src/restart-service/.build. Again just a test here to see if it’s parcel related. Looks like it’s not?

Read more comments on GitHub >

github_iconTop Results From Across the Web

NPM package `pem` doesn't seem to work in AWS lambda ...
I launched an Amazon Linux 2 server, built OpenSSL on it, transferred the package to my local machine, and deployed it via Serverless....
Read more >
AWS Lambda function errors in Node.js
This page describes how to view Lambda function invocation errors for the Node.js runtime using the Lambda console and the AWS CLI.
Read more >
How We Debugged And Fixed 'EMFILE: too many files open ...
This article shows how we debugged and fixed an 'EMFILE: too many files open' error on AWS Lambda.
Read more >
AWS Lambda Timeout Best Practices - Lumigo
Take charge of AWS Lambda timeouts and learn how to prevent timeout errors and service disruptions.
Read more >
AWS CDK - One-Step S3 Websites with esbuild
I wrote previously about using aws-lambda-nodejs with esbuild to write ... so I'm just pulling an alpine image to give an error message....
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