[@aws-cdk/aws-lambda-nodejs] Parcel v2 but Docker still needed
The Question
According to docs https://docs.aws.amazon.com/cdk/api/latest/docs/aws-lambda-nodejs-readme.html if using Parcel v2, docker will not be necessary during build.
After adding parcel v2 and running the build in codepipeline, i still get the message that docker is required. In fact cause of lack of permission, i am getting Cannot connect to the Docker daemon at unix:///var/run/docker.sock
But why is docker needed with Parcel v2? Or did i read the docs wrong?
Environment
- CDK CLI Version: 1.61.0
Hi @logemann,
Can you share more details about your environment? Code example + how did you add Parcel v2?
Thanks
i added "parcel": "^2.0.0-beta.1"
as devDependency in my typescript project's package.json (and of course "@aws-cdk/aws-lambda-nodejs") and then i used NodeJsFunction in my stack. Then in my buildspec in CodeBuild i just triggered "cdk deplpy".
I am using lerna packages but i dont think that this is related somehow.
Can you run node -p "require('child_process').spawnSync(require.resolve('parcel'), ['--version']).stdout.toString().trim()"?
@jogold I've faced the same issue and this command prints nothing
So when I'm building the project I see the following:
Incorrect parcel version detected: <> 2.0.0-beta.1. Switching to Docker bundling.
As you can see here should be {version} <> 2.0.0-beta.1
And instead of version we have empty string it seems
@rychkog if it prints nothing can you try with stderr?
node -p "require('child_process').spawnSync(require.resolve('parcel'), ['--version']).stderr.toString().trim()"
@jogold FWIW I too am experiencing this issue.
I pinned Parcel to 2.0.0-beta.1 in my package.json, and the following shows its as available/discoverable from my project root.
❯ node -p "require('child_process').spawnSync(require.resolve('parcel'), ['--version']).stdout.toString().trim()"
2.0.0-beta.1
I was really hoping up-taking 1.62.0 would at least lead me to the 'Incorrect parcel version detected ...' error. But we don't even get that far. So I went ahead and updated the catch block of the 'runsLocally()' method in the LocalBundler class of bundlers.js to print the caught error. For whatever reason, I'm getting: Error: Cannot find module 'parcel' (again even though I can see it w/out when executing via node directly.)
I'll keep digging to see if I can find anything of use, but figured I'd share my current state regardless.
Do you have a globally installed aws-cdk?
Yes I do.
Maybe worth mentioning, the CDK project itself is written in python. However some of the lambda functions we're deploying are node projects written in typescript. They bundle just fine within the Docker environment, but we also use docker with the CDK for other purposes, and at the moment this is creating a 'docker in docker' scenario for those situations.
Maybe worth mentioning, the CDK project itself is written in python. However some of the lambda functions we're deploying are node projects written in typescript.
Can you share your folder structure?
Can you share your folder structure?
Sorry for the delay in getting back to you. I'm currently structuring projects which include lambda deployments as follows (though I'm certainly open to alternatives):
project/
├── .babelrc
├── .dockerignore
├── .env
├── .git
├── .gitignore
├── Dockerfile
├── app.py
├── cdk.context.json
├── cdk.json
├── app_support_code
│ ├── __init__.py
│ ├── construct_abstraction1.py
│ └── construct_abstraction2.py
├── lambda_functions
│ ├── func1
│ │ ├── supp1.ts
│ │ ├── index.ts
│ │ ├── supp2.ts
│ │ └── supp3.ts
│ ├── func2
│ │ └── index.js
│ ├── func3
│ │ └── index.js
│ ├── func4
│ │ └── index.js
│ └── func5
│ └── index.js
├── package.json
├── requirements.txt
├── setup.py
└── tsconfig.json
Lambda functions reside in the lambda_functions directories, and we reference this directory as needed when defining lambda functions for deployment.
Here's an example of a function definition from a stack/construct which might be defined in project/app_support_code/construct_abstraction1.py:
func1_lambda = aws_lambda_nodejs.NodejsFunction(
self,
"func1-lambda",
entry=pathlib.Path(__file__).joinpath("../../lambda_functions/func1/index.ts").resolve().as_posix(),
project_root=pathlib.Path(__file__).parent.parent.resolve().as_posix(),
minify=True,
runtime=aws_lambda.Runtime.NODEJS_12_X,
description="useful description here",
parcel_environment={"BUILD_ENVVAR": something_useful_from_stack},
)
@kclark1117 would you be able to try replacing the files bundlers.js and bundling.js with the ones provided here https://gist.github.com/jogold/4baef3ac15a354f086cfc03ade1a385d?
What happens is that Parcel is available in your project but the detection occurs outside your project folder. The files in the gist should fix this.
@logemann @rychkog can you try running those commands?
node -p "require('child_process').spawnSync(require.resolve('parcel'), ['--version']).stdout.toString().trim()"
node -p "require('child_process').spawnSync(require.resolve('parcel'), ['--version']).stderr.toString().trim()"
@kclark1117 would you be able to try replacing the files
bundlers.jsandbundling.jswith the ones provided here https://gist.github.com/jogold/4baef3ac15a354f086cfc03ade1a385d?What happens is that Parcel is available in your project but the detection occurs outside your project folder. The files in the gist should fix this.
Ahh, yeah that makes sense (in hindsight).
The changes from your gist worked like a charm!
@SomayaB can you add a resonse-requested label here? thx
I've been watching for this issue because I've also been having trouble with the "local parcel" feature under Windows 10.
On my Mac, Docker-based builds work reliably but they're very slow. Installing Parcel as per the instructions enabled faster "local parcel" as expected.
On my work Windows 10 PC, Docker-based builds have been intermittently failing with various different errors since CDK 1.58 and I've been hoping to use the "local parcel" to avoid those issues. However, even with CDK 1.64 and having parcel 2.0.0-beta.1 installed locally, it still tries to build with Docker.
Both computers have Node 12.8.4 and Docker 19.03.12.
I've been watching for this issue because I've also been having trouble with the "local parcel" feature under Windows 10.
On my Mac, Docker-based builds work reliably but they're very slow. Installing Parcel as per the instructions enabled faster "local parcel" as expected.
On my work Windows 10 PC, Docker-based builds have been intermittently failing with various different errors since CDK 1.58 and I've been hoping to use the "local parcel" to avoid those issues. However, even with CDK 1.64 and having parcel 2.0.0-beta.1 installed locally, it still tries to build with Docker.
Both computers have Node 12.8.4 and Docker 19.03.12.
Are you using WSL2 on Windows?
I have WSL 1 installed, but I've been building within Git Bash instead. (occasionally checking cmd)
I have WSL 1 installed, but I've been building within Git Bash instead. (occasionally checking cmd)
Local bundling is currently not supported on Windows. The only alternative I can recommend is WSL2, performances are good even with Docker (using the WSL2 engine then).
OK thanks. I guess I must have missed that in the documentation.