AWSCloudShell - CDK Bootstrap failure with NodeJS version 16 EOL, how to upgrade?

969 Views Asked by At

I am following a tutorial on CDK using AWSCloudShell, and installed it using npm command:

sudo npm install -g aws-cdk

However, when I tried running the CDK command cdk bootstrap provides this error:

cdk bootstrap
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!                                                                            !!
!!  Node 16 has reached end-of-life on 2023-09-11 and is not supported.       !!
!!  Please upgrade to a supported node version as soon as possible.           !!
!!                                                                            !!
!!  This software is currently running on node v16.20.2.                      !!
!!  As of the current release of this software, supported node releases are:  !!
!!  - ^20.0.0 (Planned end-of-life: 2026-04-30)                               !!
!!  - ^18.0.0 (Planned end-of-life: 2025-04-30)                               !!
!!                                                                            !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
node:internal/modules/cjs/loader:1031
node:internal/modules/cjs/loader:1031
  throw err;
  ^

Error: Cannot find module '@aws-cdk/core'
Require stack:
- /home/cloudshell-user/cdk-app/lib/cdk-app-stack.js
- /home/cloudshell-user/cdk-app/bin/cdk-app.js
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1028:15)
    at Function.Module._load (node:internal/modules/cjs/loader:873:27)
    at Module.require (node:internal/modules/cjs/loader:1100:19)
    at require (node:internal/modules/cjs/helpers:119:18)
    at Object.<anonymous> (/home/cloudshell-user/cdk-app/lib/cdk-app-stack.js:1:13)
    at Module._compile (node:internal/modules/cjs/loader:1198:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
    at Module.load (node:internal/modules/cjs/loader:1076:32)
    at Function.Module._load (node:internal/modules/cjs/loader:911:12)
    at Module.require (node:internal/modules/cjs/loader:1100:19) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/home/cloudshell-user/cdk-app/lib/cdk-app-stack.js',
    '/home/cloudshell-user/cdk-app/bin/cdk-app.js'
  ]
}

Subprocess exited with error 1

It appears that we need to use node 18.x or 20.x, but after trying to install these using nvm from their github (https://github.com/nvm-sh/nvm), and then performing nvm install 18 for example, but then experienced these errors:

[cloudshell-user@ip-x-y-z ~]$ node --version
node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by node)
node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by node)

Overall, I think this might be the wrong path, and wondering what I should do to resolve this, since I'm not sure I can add these dependencies to the underlying Amazon Linux 2 instance powering the AWS Cloudshell. Any insight? Thank you!

1

There are 1 best solutions below

1
pepitoenpeligro On

As you say, AWS CloudShell comes with NodeJS 16 version enter image description here.

AWS CDK breaks with NodeJS 16 on 2.33.0 but not with <=2.32.0 enter image description here

The latest AWS CDK version is 2.96.2, which is very distant in time with the version that breaks nodejs by default in AWS CloudShell, so it is not recommended to use it at all.

You will not be able to install nodejs18 on AMI 4.14.255-314-253.539.amzn2.x86_64 cause of its glibc version (2.26) and nodejs18 needs glibc@28 or greater.

Also you will not be able to use nvm for the same root issue.

Alternatively you could boostrap the environment with cdk from AWS Cloud9. Cloud9 builds an IDE with nvm and docker pre-installed. My personal recommendation is to use docker, as you can see in the next picture. The Cloud9 backend instance will be automatically shut down after 30 minutes of non-use (you can configure this in the cloud9 launch panel).

$ docker run --rm -it node:18.17.1-slim bash
$ npm install -g [email protected]
$ npm notice Run npm install -g [email protected] to update!
$ cdk --version
$ cdk bootstrap --dry-run

enter image description here