AWS CDK Builder
Expert in building AWS infrastructure using CDK with TypeScript, leveraging L2/L3 constructs and Well-Architected Framework patterns.
Activation Triggers
Activate on: "AWS CDK", "CDK construct", "CDK stack", "CDK pipeline", "AWS IaC TypeScript", "L2 construct", "CDK patterns", "cdk deploy", "cdk synth"
NOT for: Terraform IaC → terraform-module-builder | Kubernetes manifests → kubernetes-manifest-generator | Serverless Framework → devops-automator
Quick Start
- Initialize CDK app —
npx cdk init app --language typescript
- Design stack structure — separate stateful (databases, buckets) from stateless (compute, APIs)
- Use L2 constructs — prefer high-level constructs over L1 CloudFormation resources
- Add CDK Nag — automated Well-Architected compliance checking
- Deploy with CDK Pipelines — self-mutating CI/CD pipeline
Core Capabilities
| Domain |
Technologies |
| CDK Core |
CDK 2.180+, Constructs library, CDK CLI, cdk.json |
| L2/L3 Constructs |
aws-lambda, aws-apigateway, aws-ecs-patterns, aws-rds |
| Compliance |
cdk-nag (AwsSolutions, NIST, HIPAA, PCI packs) |
| CI/CD |
CDK Pipelines, CodePipeline, CodeBuild, self-mutation |
| Patterns |
ECS Fargate patterns, API Gateway + Lambda, S3 + CloudFront |
Architecture Patterns
Stack Organization (Stateful vs Stateless)
// bin/app.ts — top-level app with environment separation
const app = new cdk.App();
// Stateful stack — rarely changes, careful with updates
const dataStack = new DataStack(app, 'Data-Prod', {
env: { account: '123456789', region: 'us-east-1' },
});
// Stateless stack — frequently deployed, safe to destroy/recreate
const apiStack = new ApiStack(app, 'Api-Prod', {
env: { account: '123456789', region: 'us-east-1' },
database: dataStack.database,
bucket: dataStack.bucket,
});
// Pipeline stack — self-mutating CI/CD
new PipelineStack(app, 'Pipeline', {
env: { account: '123456789', region: 'us-east-1' },
});
L2 Construct with Best Practices
// lib/api-stack.ts
export class ApiStack extends cdk.Stack {
constructor(scope: Construct, id: string, props: ApiStackProps) {
super(scope, id, props);
const handler = new lambda.Function(this, 'Handler', {
runtime: lambda.Runtime.NODEJS_22_X,
handler: 'index.handler',
code: lambda.Code.fromAsset('lambda/'),
memorySize: 256,
timeout: cdk.Duration.seconds(30),
tracing: lambda.Tracing.ACTIVE, // X-Ray
insightsVersion: lambda.LambdaInsightsVersion.VERSION_1_0_229_0,
environment: {
TABLE_NAME: props.table.tableName,
POWERTOOLS_SERVICE_NAME: 'api', // Lambda Powertools
},
});
props.table.grantReadWriteData(handler); // Least privilege
const api = new apigw.RestApi(this, 'Api', {
deployOptions: {
tracingEnabled: true,
metricsEnabled: true,
throttlingRateLimit: 1000,
throttlingBurstLimit: 500,
},
});
api.root.addResource('items').addMethod('GET',
new apigw.LambdaIntegration(handler));
}
}
CDK Pipelines (Self-Mutating)
Source (GitHub) → Synth (cdk synth) → Self-Mutate
│ │
▼ ▼
UpdatePipeline ─── Deploy Staging ─── Manual Approval ─── Deploy Prod
│ │
Integration Tests Smoke Tests
Anti-Patterns
- L1 constructs everywhere — using
CfnBucket instead of s3.Bucket. L2 constructs encode best practices (encryption, logging, access control) by default.
- Monolithic stacks — one stack with 200+ resources hits CloudFormation limits and deploys slowly. Split into stateful/stateless stacks with cross-stack references.
- Missing cdk-nag — deploying without compliance checks. Add
Aspects.of(app).add(new AwsSolutionsChecks()) to catch security issues pre-deploy.
- Hardcoded account/region —
account: '123456789' in construct code. Use cdk.json context or cdk.Environment lookup for portability.
- No snapshot tests — CDK generates CloudFormation templates that change unexpectedly. Add
expect(template).toMatchSnapshot() tests to detect unintended changes.
Quality Checklist
[ ] Stacks separated: stateful (data) vs stateless (compute)
[ ] L2/L3 constructs used (not raw CloudFormation L1)
[ ] cdk-nag enabled with AwsSolutions pack
[ ] Snapshot tests for all stacks
[ ] CDK Pipelines for self-mutating CI/CD
[ ] Least privilege IAM via grant methods (grantRead, grantWrite)
[ ] cdk synth produces valid CloudFormation
[ ] Cross-stack references use exported outputs
[ ] Removal policies set (RETAIN for production data, DESTROY for dev)
[ ] Tags applied via Aspects for cost allocation
[ ] cdk diff reviewed before every deployment
[ ] Lambda functions use Powertools for observability
1---2license: Apache-2.03name: aws-cdk-builder4description: "AWS CDK infrastructure builder using TypeScript with L2/L3 constructs and Well-Architected patterns. Activate on: AWS CDK, CDK construct, CDK stack, CDK pipeline, AWS infrastructure as code TypeScript, L2 construct, CDK patterns. NOT for: Terraform IaC (use terraform-module-builder), Kubernetes manifests (use kubernetes-manifest-generator), serverless framework (use devops-automator)."5allowed-tools: Read,Write,Edit,Bash(docker:*,kubectl:*,terraform:*,npm:*,npx:*)6category: DevOps & Infrastructure7tags:8 - aws9 - cdk10 - iac11 - typescript12pairs-with:13 - skill: terraform-iac-expert14 reason: Alternative IaC approach for multi-cloud; CDK is AWS-native15 - skill: terraform-module-builder16 reason: Terraform modules solve the same reusability problem CDK constructs solve17metadata:18 source: https://skillmd.com/skills/curiositech/aws-cdk-builder19---2021# AWS CDK Builder2223Expert in building AWS infrastructure using CDK with TypeScript, leveraging L2/L3 constructs and Well-Architected Framework patterns.2425## Activation Triggers2627**Activate on:** "AWS CDK", "CDK construct", "CDK stack", "CDK pipeline", "AWS IaC TypeScript", "L2 construct", "CDK patterns", "cdk deploy", "cdk synth"2829**NOT for:** Terraform IaC → `terraform-module-builder` | Kubernetes manifests → `kubernetes-manifest-generator` | Serverless Framework → `devops-automator`3031## Quick Start32331. **Initialize CDK app** — `npx cdk init app --language typescript`342. **Design stack structure** — separate stateful (databases, buckets) from stateless (compute, APIs)353. **Use L2 constructs** — prefer high-level constructs over L1 CloudFormation resources364. **Add CDK Nag** — automated Well-Architected compliance checking375. **Deploy with CDK Pipelines** — self-mutating CI/CD pipeline3839## Core Capabilities4041| Domain | Technologies |42|--------|-------------|43| **CDK Core** | CDK 2.180+, Constructs library, CDK CLI, cdk.json |44| **L2/L3 Constructs** | aws-lambda, aws-apigateway, aws-ecs-patterns, aws-rds |45| **Compliance** | cdk-nag (AwsSolutions, NIST, HIPAA, PCI packs) |46| **CI/CD** | CDK Pipelines, CodePipeline, CodeBuild, self-mutation |47| **Patterns** | ECS Fargate patterns, API Gateway + Lambda, S3 + CloudFront |4849## Architecture Patterns5051### Stack Organization (Stateful vs Stateless)5253```typescript54// bin/app.ts — top-level app with environment separation55const app = new cdk.App();5657// Stateful stack — rarely changes, careful with updates58const dataStack = new DataStack(app, 'Data-Prod', {59 env: { account: '123456789', region: 'us-east-1' },60});6162// Stateless stack — frequently deployed, safe to destroy/recreate63const apiStack = new ApiStack(app, 'Api-Prod', {64 env: { account: '123456789', region: 'us-east-1' },65 database: dataStack.database,66 bucket: dataStack.bucket,67});6869// Pipeline stack — self-mutating CI/CD70new PipelineStack(app, 'Pipeline', {71 env: { account: '123456789', region: 'us-east-1' },72});73```7475### L2 Construct with Best Practices7677```typescript78// lib/api-stack.ts79export class ApiStack extends cdk.Stack {80 constructor(scope: Construct, id: string, props: ApiStackProps) {81 super(scope, id, props);8283 const handler = new lambda.Function(this, 'Handler', {84 runtime: lambda.Runtime.NODEJS_22_X,85 handler: 'index.handler',86 code: lambda.Code.fromAsset('lambda/'),87 memorySize: 256,88 timeout: cdk.Duration.seconds(30),89 tracing: lambda.Tracing.ACTIVE, // X-Ray90 insightsVersion: lambda.LambdaInsightsVersion.VERSION_1_0_229_0,91 environment: {92 TABLE_NAME: props.table.tableName,93 POWERTOOLS_SERVICE_NAME: 'api', // Lambda Powertools94 },95 });9697 props.table.grantReadWriteData(handler); // Least privilege9899 const api = new apigw.RestApi(this, 'Api', {100 deployOptions: {101 tracingEnabled: true,102 metricsEnabled: true,103 throttlingRateLimit: 1000,104 throttlingBurstLimit: 500,105 },106 });107108 api.root.addResource('items').addMethod('GET',109 new apigw.LambdaIntegration(handler));110 }111}112```113114### CDK Pipelines (Self-Mutating)115116```117Source (GitHub) → Synth (cdk synth) → Self-Mutate118 │ │119 ▼ ▼120UpdatePipeline ─── Deploy Staging ─── Manual Approval ─── Deploy Prod121 │ │122 Integration Tests Smoke Tests123```124125## Anti-Patterns1261271. **L1 constructs everywhere** — using `CfnBucket` instead of `s3.Bucket`. L2 constructs encode best practices (encryption, logging, access control) by default.1282. **Monolithic stacks** — one stack with 200+ resources hits CloudFormation limits and deploys slowly. Split into stateful/stateless stacks with cross-stack references.1293. **Missing cdk-nag** — deploying without compliance checks. Add `Aspects.of(app).add(new AwsSolutionsChecks())` to catch security issues pre-deploy.1304. **Hardcoded account/region** — `account: '123456789'` in construct code. Use `cdk.json` context or `cdk.Environment` lookup for portability.1315. **No snapshot tests** — CDK generates CloudFormation templates that change unexpectedly. Add `expect(template).toMatchSnapshot()` tests to detect unintended changes.132133## Quality Checklist134135```136[ ] Stacks separated: stateful (data) vs stateless (compute)137[ ] L2/L3 constructs used (not raw CloudFormation L1)138[ ] cdk-nag enabled with AwsSolutions pack139[ ] Snapshot tests for all stacks140[ ] CDK Pipelines for self-mutating CI/CD141[ ] Least privilege IAM via grant methods (grantRead, grantWrite)142[ ] cdk synth produces valid CloudFormation143[ ] Cross-stack references use exported outputs144[ ] Removal policies set (RETAIN for production data, DESTROY for dev)145[ ] Tags applied via Aspects for cost allocation146[ ] cdk diff reviewed before every deployment147[ ] Lambda functions use Powertools for observability148```