How to set up your AWS Cloud Development Kit (CDK) environment for the First Time

Hamza Shabbir
2 min readJul 8, 2022

--

Amazon Web Services (AWS) Cloud Development Kit or CDK provides an abstraction layer and a High-Level framework to write your Cloudformation Template using languages such as Python, Javascript, Java, Typescript, and C#. This gives Engineers many benefits.

CDK eliminates the use of writing direct cloud formation templates which is a difficult task. Now Engineers can write the entire infrastructure as code (IaC) using their favorite programming language with all the key concepts such as parameters, conditionals, loops, composition, and inheritance to model the application and system design. CDK also allows best software engineering practices such as code reviews, unit tests, and source control to make your infrastructure more robust. The CDK Construct Library has built-in Classes for all AWS Services and comes with extensive documentation. Developers, DevOps Engineers, and Cloud Engineers can use the CDK Library in their IDEs such as VS Code and Build and connect the entire Infrastructure in the Cloud. To get started with AWS CDK first Install Windows Subsystem for Linux. Open the Windows Power Shell in administrator mode and enter the following commands or in VS Code Terminal.

Note: This Setup is only for a Windows Machine and a Python Environment. For Other language Setup, please refer to AWS Documentation.

Now cd into the directory you want to make your CDK project and run the following to install further dependencies such as nvm.

  • Now, we will create a virtual environment in python and initialize our CDK project. First, we will need to install the python-venv module. Then use the cdk init command to initialize the empty cdk project. This will make the directory structure containing stack and test directories.

Note: The CDK init command should always bcontaine run in an empty directory.

AWS CDK Environment
This is what the directory structure will look like including the stack file.

To deploy the synthesized cloud formation template first you need to configure your aws account in the VS Code terminal. Generated your AWS secret access key from IAM >User>”your user”>security credentials. Then run the following commands and give the required credentials. Leave the Default output format option empty and press enter. Afterr the configuration is done properly finally enter cdk deploy and the cloudformation template will be deployed to AWS in your specified region.

Note: always keep your AWS Access Key ID and AWS Secret Access Key safe with you and not share them with anyone.

aws configureAWS Access Key ID
AWS Secret Access Key
Default Region us-west-1
Default output format
cdk deploy

Congratulations! Now you are ready to work with AWS CDK and write your applications using aws infrastructure.

--

--

Hamza Shabbir

Backend Developer @Markaz Technologies (YC-W22) 🚀☁️ | AWS Community Builder👷‍♂️