Lesson 18 of 30
CDK doesn't replace CloudFormation — it's a compiler that generates it, which means every stack, change set, and drift rule from the CloudFormation lesson still applies underneath.
11 min read
Every option explains itself — why the right one is right, and why each wrong one is wrong. Miss one and it comes back later on a spaced-repetition schedule.
Question 1 of 3
A team writes their infrastructure using CDK in TypeScript instead of hand-written CloudFormation YAML. What actually happens when they run `cdk deploy`?
Hints without spoilers, and a plain explanation of why a wrong answer was wrong — answered only from this lesson. Free account, no card.
Sign up freeWhat interviewers actually ask about this, and what a strong answer has to cover.
A strong answer covers
Likely follow-ups
The CDK (Cloud Development Kit) lets infrastructure be authored in a real programming language — TypeScript, Python, and others — instead of raw CloudFormation YAML or JSON. You write classes and function calls describing the resources you want; running cdk synth compiles that code down into an actual CloudFormation template, and cdk deploy hands that template to CloudFormation exactly the same way a hand-written YAML file would be. CDK is a code generator sitting on top of CloudFormation, not a separate deployment engine — every stack, change set, and drift concept from the CloudFormation lesson is still exactly what's running underneath.
The building block is a construct — a composable unit representing one or more resources, at three levels:
import * as s3 from "aws-cdk-lib/aws-s3";
new s3.Bucket(this, "UploadsBucket", {
versioned: true,
});
This is the CDK equivalent of the AWS::S3::Bucket resource from the CloudFormation lesson's template — same versioned bucket, same underlying resource type, but written as a typed constructor call instead of a YAML block. cdk synth turns it into an actual CloudFormation template you can inspect directly; cdk diff is the CDK-level equivalent of reviewing a change set before committing to it.
cdk deploy still goes through CloudFormation's real stacks and change sets underneath. Nothing about drift, stack deletion cascading to everything it manages, or change sets as a review gate changes just because the authoring layer is nicer — CDK doesn't introduce a different deployment model, it generates input for the same one.AWS::S3::Bucket block don't necessarily produce identical templates — the defaults CDK chooses (naming, encryption, removal behavior) are worth knowing rather than assuming.cdk synth output is plain, readable CloudFormation — when a deploy behaves unexpectedly, reading the actual synthesized template to see what CDK generated is a legitimate and sometimes necessary debugging step."Why would a team choose CDK over raw CloudFormation?" tests whether a candidate can name the real, specific value — a real programming language's tooling (types, loops, reusable constructs) generating the same underlying CloudFormation stacks — rather than a vague "it's easier," and whether they understand a CDK deploy failure could be either the CDK code or the CloudFormation stack it synthesized, which changes where you'd look first.