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
| Aspect | CDK | Terraform | CloudFormation |
|---|---|---|---|
| Language | TypeScript, Python, etc. | HCL | YAML/JSON |
| Abstraction | High-level constructs | Resources | Resources |
| Multi-cloud | No | Yes | No |
| State | CloudFormation | Terraform state | CloudFormation |
Key concepts
| Concept | Function | Example |
|---|---|---|
| App | Entry point, contains stacks | new cdk.App() |
| Stack | Deployment unit (= CloudFormation stack) | MyServiceStack |
| Construct L1 | 1:1 mapping with CloudFormation | CfnBucket (low level) |
| Construct L2 | Abstractions with sensible defaults | s3.Bucket (auto permissions, encryption) |
| Construct L3 | Complete patterns | LambdaRestApi (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
- CDK Documentation — Official documentation.
- CDK Patterns — Architecture patterns.
- CDK Best Practices — AWS, 2024. Official best practices.