Concepts

AWS CDK

AWS infrastructure as code framework that allows defining cloud resources using programming languages like TypeScript, Python, or Java, generating CloudFormation.

seed#aws#cdk#iac#typescript#cloudformation#devops

What it is

AWS CDK (Cloud Development Kit) is an infrastructure as code framework that allows defining AWS resources using real programming languages instead of YAML/JSON. Code is synthesized to CloudFormation for deployment.

CDK vs Terraform vs CloudFormation

AspectCDKTerraformCloudFormation
LanguageTypeScript, Python, etc.HCLYAML/JSON
AbstractionHigh-level constructsResourcesResources
Multi-cloudNoYesNo
StateCloudFormationTerraform stateCloudFormation

Key concepts

ConceptFunctionExample
AppEntry point, contains stacksnew cdk.App()
StackDeployment unit (= CloudFormation stack)MyServiceStack
Construct L11:1 mapping with CloudFormationCfnBucket (low level)
Construct L2Abstractions with sensible defaultss3.Bucket (auto permissions, encryption)
Construct L3Complete patternsLambdaRestApi (API + Lambda + permissions)

TypeScript example

const fn = new lambda.Function(this, 'Handler', {
  runtime: lambda.Runtime.NODEJS_20_X,
  handler: 'index.handler',
  code: lambda.Code.fromAsset('lambda'),
});
 
const api = new apigateway.RestApi(this, 'Api');
api.root.addMethod('GET', new apigateway.LambdaIntegration(fn));

Why it matters

CDK allows defining infrastructure with real programming languages, enabling abstractions, unit testing, and pattern reuse that are not possible with HCL or YAML. For development teams that already master TypeScript or Python, it lowers the barrier to entry for IaC.

References

Concepts