How to install AWS CDK on Amazon Linux 2023

Developers require the AWS Cloud Development Kit (CDK) to provision and manage AWS resources using languages such as TypeScript, Python, Java, and C#. CDK is an open-source software development framework provided by Amazon Web Services. This allows a higher level of abstraction and enables infrastructure to be defined as code, making it easier to manage, maintain, and scale.

Key features of AWS CDK include declarative Syntax and multiple programming languages support; pre-built constructs; integrates seamlessly with popular development tools and environments, offers modularity and reusability.

Steps to install NodeJs and CDK on Amazon Linux 2023

1. Connect and Update AL2023

First of all connect to your Amazon Linux 2023 terminal, for that, we can directly use the AWS browser-based SSH client available right on the AWS Dashboard or use the local PC terminal with private and SSH. Once you have established the connection and have the terminal access, run the system update command.

sudo dnf update

2: Add NodeJs repository

While doing this article the latest version of Nodejs is available to install through Amazon Linux was 18. x, however, here we are going for 20.x, and for that, we are adding its repository.

sudo su 
curl -fsSL https://rpm.nodesource.com/setup_lts.x | bash -
dnf update

3. Install Node.js and npm

We need NodeJs on Amazon Linux 2023 along with its package manager called NPM to install and update CDK. Therefore, install Node.js and npm using the default package manager of Amazon.

sudo dnf install nodejs
Add NodeJs repostiory on Amazon Linux 2023

Verify the installation:

After completing the Node installation, check its version to confirm it is on the system along with the package manager.

node --version
npm --version
Check version

4: Install AWS CDK on Amazon Linux 2023

Finally, using the NPM install the AWS CDK on Amazon Linux 2023, this applies not only to this Linux but even others including Windows, which means we can run AWS CDK with the help of the Node package manager on any operating system.

sudo npm install -g aws-cdk

Verify the installation:

cdk --version
check AWS CDK version

5: Configure AWS Credentials

To deploy infrastructure to AWS using CDK, users must first configure their AWS credentials on Amazon Linux using the AWS CLI. So, run the given command and enter the AWS Access Key ID, Secret Access Key, default region, and output format.

aws configure

6: Test CDK Installation

To verify that CDK is installed correctly on our Amazon Linux 2023, we can create a simple CDK project to deploy it to AWS.

Create a new directory for your CDK project:

mkdir my-cdk-project
cd my-cdk-project

Initialize a new CDK project using the preferred programming language (e.g., TypeScript):

cdk init app --language typescript

Build and deploy the CDK stack to AWS:

npm run build
cdk deploy

For more information visit the official documentation.

Conclusion:

We have just shown the installation steps to get AWS CDK on Amazon Linux 2023 Instance, however, you would need to spend some time on the official documentation of this tool to understand it clearly. Check out our other tutorials on AL2023:

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.