Learn/Labs
Labs · 16 min read · August 2026
AWS CDK Starter: One Stack, One Bucket, No Click-Ops
Infrastructure as code the way AWS documents CDK: app, stack, construct, synth, deploy — starting with a locked-down S3 bucket.
Source. AWS CDK Developer Guide · CDK workshop concepts
Abstract & theoretical context
The AWS Cloud Development Kit (CDK) lets you define CloudFormation in TypeScript (or Python). An App contains Stacks; stacks contain Constructs. synth emits a template; deploy applies it. Clicking a bucket in the console does not teach change-sets. This lab is the smallest official path: CDK app, S3 bucket with Block Public Access, destroy when done.
Models, formulas & variables
1. Construct tree
App → Stack → Construct(s) → CloudFormation resources
- — L1 constructs map 1:1 to CloudFormation. L2 adds defaults and methods.
- — Ids must be unique in the stack. Renaming an id often replaces the resource.
2. Lifecycle
cdk synth → cdk diff → cdk deploy → cdk destroy
- — Never deploy to an account you cannot afford to empty.
- — Bootstrap (cdk bootstrap) is required once per account/Region.
Reference implementation
Copy into a sandbox account. Pin Region ap-south-1 unless the lab says otherwise.
lib/lab-stack.ts
AWS CDK · TypeScript
import * as cdk from "aws-cdk-lib";
import * as s3 from "aws-cdk-lib/aws-s3";
import { Construct } from "constructs";
export class LabStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
new s3.Bucket(this, "LabBucket", {
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
encryption: s3.BucketEncryption.S3_MANAGED,
removalPolicy: cdk.RemovalPolicy.DESTROY,
autoDeleteObjects: true,
});
}
}Lab procedure
- 01Install Node 18+, AWS CLI, and cdk (`npm i -g aws-cdk`).
- 02Run cdk bootstrap in the lab account/Region once.
- 03cdk init app --language typescript, replace the stack with the snippet above.
- 04cdk diff, then cdk deploy. Confirm Block Public Access in the S3 console.
- 05cdk destroy. Do not leave empty stacks as litter.
Key insights
- CDK is CloudFormation with types. You still own IAM and cost.
- removalPolicy RETAIN is safer in prod and annoying in a two-hour lab.
- Hotswap is a later trick. Learn deploy/destroy first.
Account & lab requirements
IAM able to create CloudFormation, S3, and the bootstrap resources. Use a sandbox.
More in Labs
Serverless API Lab: API Gateway + Lambda
HTTP API in front of Lambda the way AWS documents it — integration, IAM invoke, stages, and the checks before you call it shipped.
CloudWatch: Logs, Metrics, and One Alarm That Matters
How AWS documents observability: log groups, namespaces, and alarms — enough to know a Lambda is broken without SSHing anywhere.