AWS CDK(Cloud Development Kit)

Divya Mishra
2 min readFeb 25, 2024

--

Basic overview of AWS CDK

CDK (Cloud development kit) is a open source software development framework. Enables writing imperative code to generate CloudFormation template .

Why CDK ?

You are free to create any number of resources for your project from AWS console but it may become messy, not reviewable, not repeatable, for example— if you want to create similar set of resources for 5 to 10 times in different regions — you might have to repeat the same task again and again.

Cloudformation

CloudFormation is one of IaC tools available in AWS ecosystem. Infrastructure as Code(IaC) is nothing but having desired state of your infrastructure in the form of code. It is available in in YAML or JSON format.

While writing cloudformation we may suffer from lengthiness, indentation issue, copy-paste at lot of places, to avoid it all CDK came into picture. Where define your cloud resources using your favorite programming language.

How CDK works ?

The CDK code, written in supported programming languages, is transformed into AWS CloudFormation templates, which are then used to create and manage resources on AWS.

Clouformation template

Let’s know some important key term used in cdk to understand better,

stack — is a smallest physical unit in cloudformation, deployed as a unit. constructs — are the basic building blocks (like, class in oops ) used to define AWS infrastructure resources. They represent AWS resources or groups of resources and can be thought of as reusable components that encapsulate the configuration and behavior of those resources.

First CDK app -

Refer this AWS document, concise and understandable.

The project structure of cdk app looks like this-

AWS CDK project structure in vscode

lib/cdk-workshop-stack.ts is where your CDK application’s main stack is defined. It looks something like this —

#!/usr/bin/env node
import * as cdk from 'aws-cdk-lib';
import { CdkWorkshopStack } from '../lib/cdk-workshop-stack';

const app = new cdk.App();
new CdkWorkshopStack(app, 'CdkWorkshopStack');

--

--

Divya Mishra

Frontend Developer. prefer reading, learning expression of writing.