Dung (Donny) Nguyen

Senior Software Engineer

AWS Cloud Development Kit (CDK)

The AWS Cloud Development Kit (CDK) is an open-source framework that lets you define cloud infrastructure using familiar general-purpose programming languages—such as TypeScript, Python, Java, C#, and Go—instead of writing raw templates. The CDK synthesizes your code into an AWS CloudFormation template, which is then deployed as a stack. This gives you the power of a real programming language (loops, conditionals, functions, classes, and packages) combined with the reliability of CloudFormation.

Why AWS CDK Exists

Writing large CloudFormation templates in YAML or JSON can be verbose and repetitive. The CDK addresses this by letting you use programming constructs to build infrastructure, enabling abstraction, reuse, and IDE support like autocompletion and type checking—while still producing standard CloudFormation under the hood.

Core Concepts

Example: Defining Infrastructure in TypeScript

import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as s3 from 'aws-cdk-lib/aws-s3';

export class MyAppStack extends cdk.Stack {
  constructor(scope: Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const bucket = new s3.Bucket(this, 'AppBucket', {
      bucketName: 'my-application-bucket',
      versioned: true,
      encryption: s3.BucketEncryption.S3_MANAGED,
      removalPolicy: cdk.RemovalPolicy.RETAIN,
    });

    new cdk.CfnOutput(this, 'BucketArn', {
      value: bucket.bucketArn,
    });
  }
}

The same infrastructure can be expressed in Python:

from aws_cdk import Stack, RemovalPolicy, CfnOutput
from aws_cdk import aws_s3 as s3
from constructs import Construct

class MyAppStack(Stack):
    def __init__(self, scope: Construct, construct_id: str, **kwargs) -> None:
        super().__init__(scope, construct_id, **kwargs)

        bucket = s3.Bucket(
            self, "AppBucket",
            bucket_name="my-application-bucket",
            versioned=True,
            encryption=s3.BucketEncryption.S3_MANAGED,
            removal_policy=RemovalPolicy.RETAIN,
        )

        CfnOutput(self, "BucketArn", value=bucket.bucket_arn)

The CDK Workflow

cdk init app --language typescript  # Scaffold a new CDK app
cdk bootstrap                       # Provision resources the CDK needs to deploy
cdk synth                           # Synthesize the CloudFormation template
cdk diff                            # Compare deployed stack with current state
cdk deploy                          # Deploy the stack to AWS
cdk destroy                         # Tear down the stack

Advantages

Considerations

CDK vs. CloudFormation

The CDK does not replace CloudFormation; it generates it. Choose the CDK when you want the expressiveness of a programming language, reusable abstractions, and strong tooling. Choose raw CloudFormation when you prefer declarative templates with no build step or programming dependency.

Conclusion

The AWS CDK brings software engineering practices to infrastructure by letting you define resources in real programming languages while still deploying through CloudFormation. With its layered construct model, reusable patterns, and rich tooling, the CDK is an excellent choice for teams that want expressive, maintainable, and reliable infrastructure as code on AWS.