Install and configure AWS Cloud Development Kit (AWS CDK)

In this article, we will learn how to install and configure AWS CDK and SAM CLI. This is a prerequisite for the AWS CDK series. There are two steps to this process: 1. Install NVM and Node.js 2. Install AWS CDK CLI using NPM 3. Install AWS SAM CLI

Now you may think why do we need to install NVM and Node.js instead when we will use Python?

Well, AWS CDK CLI is mainly available as a NPM package so installing it from NPM is the easiest way. This allows us to use the CDK CLI to create and manage CDK projects.

The actual CDK project will be written in Python but we will use the CDK CLI to create and manage the project.

Prerequisites

  1. AWS CLI: Follow the guide here to install and configure AWS CLI for your operating system.
  2. AWS SAM CLI: Follow the guide here to install and configure AWS SAM CLI for your operating system.

Install NPM & Node.js

  1. For WSL2 on Windows 10/11 or Linux
  2. For Windows 10/11
  3. For MacOS

For WSL2 on Windows 10/11 or Linux

We will be using Ubuntu 22.04 LTS on WSL2 on Windows 10/11 for this series. But this guide should work for any other version. We will install NVM, Node.js, AWS CDK, and AWS SAM CLI.

a) Let's first make sure curl is installed.

sudo apt-get install curl -y

b) Then, install NVM & NPM using the following command.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/master/install.sh | bash

c) Then, restart the shell then run the below command to verify that NVM is installed.

nvm --version

d) Now, install Node.js using the following command. I prefeer installing the LTS version to ensure a bug-free experience.

nvm install --lts

Install Node.js using NVM

After this, jump to the Install AWS CDK CLI section.

For Windows 10/11

If WSL2 is not available, you can install Node.js on Windows 10/11 directly.

a) First, install nvm-windows by downloading the installer from here. Install nvm-windows

b) Confirm the installation by running the following command in PowerShell.

nvm --version

c) Finally, install Node.js using the following command.

nvm install lts

Install Node.js using nvm-windows

After this, jump to the Install AWS CDK CLI section.

For MacOS

a) For MacOS, you need homebrew installed. If you don't have it installed, you can install it using the following command.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

b) Add homebrew to your PATH by running the following command.

echo "# Homebrew\nexport PATH=/opt/homebrew/bin:\$PATH" >> .zshrc

c) Then, restart the shell.

source ~/.zshrc

d) Install nvm using the following command.

brew install nvm

e) We will need to create a directory for nvm to store its files. Run the following command to create the directory.

mkdir ~/.nvm

f) Then, nvm to to your ~/.zshrc profile.

echo "export NVM_DIR=~/.nvm\nsource \$(brew --prefix nvm)/nvm.sh" >> .zshrc

g) Restart the shell again.

source ~/.zshrc

h) Finally, install Node.js using the following command.

nvm install --lts

Install AWS CDK CLI

Now that we have installed NVM and Node.js, we can install AWS CDK CLI using NPM.

Run the following command to install AWS CDK CLI.

npm install -g aws-cdk

Install AWS CDK CLI

Need Help? Open a discussion thread on GitHub.

Related Posts