2
votes

aws cdk returns jsii error on empty stack. Steps to reproduce are at the hello world level which makes me think that I have a version mismatch somewhere. I have re-installed aws cli, cdk and nodejs. Any suggestions on what to look for?

Steps to reproduce:

mkdir myfolder
cdk init --language python
.env\Scripts\activate.ps1
python -m pip install -r requirements.txt
cdk synth

Returns error AND an empty stack:

(.env) p$[myfolder]> cdk synth                                                                                                                      d:\myfolder\.env\lib\site-packages\jsii\_embedded\jsii\jsii-runtime.js:13295
                    throw e;
                    ^

Error: EOF: end of file, read
    at Object.readSync (fs.js:592:3)
    at SyncStdio.readLine (d:\myfolder\.env\lib\site-packages\jsii\_embedded\jsii\jsii-runtime.js:13278:33)
    at InputOutput.read (d:\myfolder\.env\lib\site-packages\jsii\_embedded\jsii\jsii-runtime.js:13203:34)
    at KernelHost.run (d:\myfolder\.env\lib\site-packages\jsii\_embedded\jsii\jsii-runtime.js:13021:32)
    at Immediate.<anonymous> (d:\myfolder\.env\lib\site-packages\jsii\_embedded\jsii\jsii-runtime.js:13029:37)
    at processImmediate (internal/timers.js:461:21) {
  errno: -4095,
  syscall: 'read',
  code: 'EOF'
}
Resources:
  CDKMetadata:
    Type: AWS::CDK::Metadata
    Properties:
      Modules: aws-cdk=1.69.0,@aws-cdk/cloud-assembly-schema=1.69.0,@aws-cdk/core=1.69.0,@aws-cdk/cx-api=1.69.0,@aws-cdk/region-info=1.69.0,jsii-runtime=Python/3.7.4
    Metadata:
      aws:cdk:path: myfolder/CDKMetadata/Default
    Condition: CDKMetadataAvailable

Environment

  - **CLI Version      :aws-cli/2.0.61 Python/3.7.7 Windows/10 exe/AMD64
  - **cdk Version:1.69.0 (build 2b474b9)
  - **Node.js Version:v14.15.0 
  - **OS               :Windows 10
  - **Language (Version):python 3.7.4  

Saw this error when I first started on cdk. But, 'cdk synth' showed a stack, so I pressed on. I was even able to 'cdk deploy' simple stacks. Eventually, as the code became only slightly more complex, jsii errors prevent stack creation. Code created by me throws errors on my machine but does NOT error on other machines. Working cdk code from other devs will not synth or deploy stacks on my machine.

So far, I have re-installed aws cli, node.js and cdk. Any ideas where the jsii error originate or how to fix them?

2

2 Answers

2
votes

For AWS-CDK on Windows, there is at least one bug in jsii documented by AWS CDK group. Deep inside the jsiiruntime (line 13278 to be exact), aws cdk group has a comment with a link to a nodejs bug report. I reported my problem to aws-cdk which seemed to be related. They reproduced the bug and created a bug report at nodejs. This bug report has links to the other bug reports. https://github.com/aws/aws-cdk/issues/11314

But I still needed a workaround. After much trial and error, the following 2 workarounds should work for AWS-CDK on Windows.

Workaround 1: replace jsii 1.14.x distro in site-packages with 1.12 or 1.13 distro. After swapping out 1.14 for 1.12 or 1.13, errors stop. Getting a distro is a trick. You will have to get one from someone who has not upgraded or run pip -- which what I did.

Workaround 2: move dev environment off Windows and onto linux or mac

0
votes

TL;DR. Expanded work arounds. (A question was asked in the AWS-CDK bug report noted above).

Workaround 1: replace jsii 1.14.x distro

Distro folders: jsii is contained in 2 folders

jsii and jsii-1.14.1.dist-info

REPLACE both of these folders with folders from an older install -- 1.12 or 1.13.

The distro folders can be found in one or both of the following locations:

Distro location virtual environment: jsii distro will be found in the site-packages directory. Example:

.env\lib\python3.8\site-packages

where virtual environment name = .env, python version = 3.8

Distro location non-virtual: This should be the location if you have not created a virtual environment. Note that, again, the python version is part of the path.

C:\Program Files\Python37\Lib\site-packages

Note: for some reason, they were not installed here. But, that may change, so keep this in mind. C:\Users\yourusername\AppData\Roaming\Python\Python37\site-packages

Workaround 2: move to linux

In windows, install WSL 2.
Install Ubuntu or your favorite linux variety.
Install python Use your favorite Windows IDE from Windows! I use Visual Studio Code. Requires installing an extension if I remember correctly.

WARNING: I had problems when trying to run python, cdk, etc where the files were on the Windows system (ex: /mnt/d/project). Just copy the repo to the "pure" linux file system ( ex: ~/project). I have git installed on the linux side and maintain my files as if it were a separate machine.