CDK constructs and synthesis
From code to infrastructure
CDK is a development kit for defining infrastructure using familiar programming languages. An app contains stacks; each stack is a deployable CloudFormation unit. Constructs are reusable building blocks in a tree. For example, an archive bucket can be declared with security and retention settings instead of building each resource by hand. Synthesis produces a cloud assembly containing templates and, where needed, asset metadata. It does not itself mean a stack has been deployed.
A private archive in TypeScript
Read this static CDK v2 example. It requires the CDK library, constructs dependency and a compatible TypeScript/Node toolchain. Exact installed versions and synthesis are not verified here. The example uses an L2 bucket construct, requests versioning, blocks public access and retains the bucket on removal. Inspect the synthesized template to confirm the actual policies, not just the source intent.
import * as cdk from 'aws-cdk-lib';import * as s3 from 'aws-cdk-lib/aws-s3';
const app = new cdk.App();const stack = new cdk.Stack(app, 'ArchiveStack');new s3.Bucket(stack, 'Archive', { blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL, versioned: true, removalPolicy: cdk.RemovalPolicy.RETAIN,});app.synth();Abstractions and assets
L1 constructs closely represent CloudFormation resource types; L2 constructs offer higher-level defaults and methods; L3 patterns combine several resources for a use case. Defaults can change with library versions. An asset may be a Lambda package or container image; review what files enter it. Bootstrap prepares an AWS environment for deployment, often with artifact storage and deployment roles. It creates real resources and requires authorization. Changing construct paths can change generated logical IDs; review possible replacement before deploying.
Review before deployment
Use a locked dependency set and reviewed source in an isolated environment. Synthesis executes application code and can involve lookups or bundling; do not assume it is offline. CDK diff can compare against deployed stacks and may access AWS. For the offline exercise compare supplied, illustrative template snapshots only. A replacement of a retained bucket still requires a data migration and cleanup plan. Do not run bootstrap or deploy.
Practice
A colleague renames the Archive construct. The proposed template removes one bucket logical ID and adds another. Decide whether to approve. Identify the data migration, retention and rollback evidence you would need. Then move to SAM for a function-focused workflow.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
CDK constructs and synthesis — knowledge check
Review infrastructure artifacts and evidence without deploying resources.
What does CDK synthesis produce?
Which construct level closely maps to CloudFormation types?
A bucket construct is renamed. What should you review first?
Why is bootstrap excluded from this offline lab?
Why inspect asset contents before deployment?