(@aws-cdk/aws-lambda-nodejs): "error: Could not resolve" while bundling without Docker
See original GitHub issueI’m trying to bundle my Lambda using NodejsFunction
but am failing. If I set forceDockerBundling
to true
(default is false
), bundling (during cdk synth
) is successful.
Reproduction Steps
this.lambdaFunction = new lambdaNodeJs.NodejsFunction(this, 'MyLambda', {
functionName: 'my-function',
runtime: lambda.Runtime.NODEJS_12_X,
memorySize: 256,
depsLockFilePath: '../lambda',
entry: '../lambda/build/index.js',
handler: 'main',
bundling: {
externalModules: ['graphql'], // I found out this might be a problem due to an error I saw when forceDockerBundling was set to true
},
environment: {
MY_FLAG: 'true',
},
});
For what it’s worth, my project is structured like:
├─ my-project
├── cdk
├── lambda
What did you expect to happen?
I expected the Lambda and (hopefully) its dependencies would be packaged using esbuild
.
What actually happened?
$ cdk synth
Bundling asset FooStack/FooLambda/MyLambda/Code/Stage...
> error: Could not resolve "../lambda/build/index.js"
1 error
Environment
- CDK CLI Version : 1.78.0
- Framework Version: 1.78.0
- Node.js Version: 12.20.0
- OS : macOS 10.15.7
- Language (Version): TypeScript 3.9.7
Other
I’ve tried setting the entry
to a file that doesn’t exist, and I get a different error altogether. So I’m pretty sure that the file is being found, but some other problem is happening.
# cdk synth
Cannot find entry file at ../lambda/build/foo.js
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (7 by maintainers)
Top Results From Across the Web
Cannot deploy Nodejs and Typescript to AWS cdk + lambda
I tried to deploy my code but i saw this error. => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: ......
Read more >class NodejsFunction (construct) · AWS CDK - Amazon.com
Java, software.amazon.awscdk.services.lambda.nodejs. ... Type: BundlingOptions (optional, default: use default bundling options: no minify, no sourcemap, ...
Read more >Troubleshooting common AWS CDK issues
When deploying my AWS CDK stack, I receive a NoSuchBucket error. Your AWS environment has not been bootstrapped, and so does not have...
Read more >aws-cdk-lib.aws_lambda_nodejs module - Amazon.com
›aws-cdk-lib.aws_lambda_nodejs ... Amazon Lambda Node.js Library ... Otherwise, bundling will happen in a Lambda compatible Docker container with the Docker ...
Read more >aws-cdk/pipelines module - AWS Documentation - Amazon.com
It is not intended to support arbitrary deployment pipelines, ... construct libraries as @aws-cdk/aws-lambda-nodejs ): Docker will run in the synth project.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Also note that the idea of the
NodejsFunction
is that you don’t have to split your project between CDK and Lambda. Everything can live together and have a common package.json file. And you can point to a TS file.I recommend the approach described in https://github.com/aws/aws-cdk/blob/v1.78.0/packages/@aws-cdk/aws-lambda-nodejs/README.md#nodejs-function where your handler lives next to the file where the
NodejsFunction
is defined.If everything lives together you can share utils and types between your infra code and Lambda code.
(also you don’t have to specify
depsLockFilePath
in this case, there’s only one lock file at the root of your repo and it will be detected)