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---2name: aws-cdk-builder3description: 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).4license: Apache-2.05---67# AWS CDK Builder89Expert in building AWS infrastructure using CDK with TypeScript, leveraging L2/L3 constructs and Well-Architected Framework patterns.1011## Activation Triggers1213**Activate on:** "AWS CDK", "CDK construct", "CDK stack", "CDK pipeline", "AWS IaC TypeScript", "L2 construct", "CDK patterns", "cdk deploy", "cdk synth"1415**NOT for:** Terraform IaC → `terraform-module-builder` | Kubernetes manifests → `kubernetes-manifest-generator` | Serverless Framework → `devops-automator`1617## Quick Start18191. **Initialize CDK app** — `npx cdk init app --language typescript`202. **Design stack structure** — separate stateful (databases, buckets) from stateless (compute, APIs)213. **Use L2 constructs** — prefer high-level constructs over L1 CloudFormation resources224. **Add CDK Nag** — automated Well-Architected compliance checking235. **Deploy with CDK Pipelines** — self-mutating CI/CD pipeline2425## Core Capabilities2627| Domain | Technologies |28|--------|-------------|29| **CDK Core** | CDK 2.180+, Constructs library, CDK CLI, cdk.json |30| **L2/L3 Constructs** | aws-lambda, aws-apigateway, aws-ecs-patterns, aws-rds |31| **Compliance** | cdk-nag (AwsSolutions, NIST, HIPAA, PCI packs) |32| **CI/CD** | CDK Pipelines, CodePipeline, CodeBuild, self-mutation |33| **Patterns** | ECS Fargate patterns, API Gateway + Lambda, S3 + CloudFront |3435## Architecture Patterns3637### Stack Organization (Stateful vs Stateless)3839```typescript40// bin/app.ts — top-level app with environment separation41const app = new cdk.App();4243// Stateful stack — rarely changes, careful with updates44const dataStack = new DataStack(app, 'Data-Prod', {45 env: { account: '123456789', region: 'us-east-1' },46});4748// Stateless stack — frequently deployed, safe to destroy/recreate49const apiStack = new ApiStack(app, 'Api-Prod', {50 env: { account: '123456789', region: 'us-east-1' },51 database: dataStack.database,52 bucket: dataStack.bucket,53});5455// Pipeline stack — self-mutating CI/CD56new PipelineStack(app, 'Pipeline', {57 env: { account: '123456789', region: 'us-east-1' },58});59```6061### L2 Construct with Best Practices6263```typescript64// lib/api-stack.ts65export class ApiStack extends cdk.Stack {66 constructor(scope: Construct, id: string, props: ApiStackProps) {67 super(scope, id, props);6869 const handler = new lambda.Function(this, 'Handler', {70 runtime: lambda.Runtime.NODEJS_22_X,71 handler: 'index.handler',72 code: lambda.Code.fromAsset('lambda/'),73 memorySize: 256,74 timeout: cdk.Duration.seconds(30),75 tracing: lambda.Tracing.ACTIVE, // X-Ray76 insightsVersion: lambda.LambdaInsightsVersion.VERSION_1_0_229_0,77 environment: {78 TABLE_NAME: props.table.tableName,79 POWERTOOLS_SERVICE_NAME: 'api', // Lambda Powertools80 },81 });8283 props.table.grantReadWriteData(handler); // Least privilege8485 const api = new apigw.RestApi(this, 'Api', {86 deployOptions: {87 tracingEnabled: true,88 metricsEnabled: true,89 throttlingRateLimit: 1000,90 throttlingBurstLimit: 500,91 },92 });9394 api.root.addResource('items').addMethod('GET',95 new apigw.LambdaIntegration(handler));96 }97}98```99100### CDK Pipelines (Self-Mutating)101102```103Source (GitHub) → Synth (cdk synth) → Self-Mutate104 │ │105 ▼ ▼106UpdatePipeline ─── Deploy Staging ─── Manual Approval ─── Deploy Prod107 │ │108 Integration Tests Smoke Tests109```110111## Anti-Patterns1121131. **L1 constructs everywhere** — using `CfnBucket` instead of `s3.Bucket`. L2 constructs encode best practices (encryption, logging, access control) by default.1142. **Monolithic stacks** — one stack with 200+ resources hits CloudFormation limits and deploys slowly. Split into stateful/stateless stacks with cross-stack references.1153. **Missing cdk-nag** — deploying without compliance checks. Add `Aspects.of(app).add(new AwsSolutionsChecks())` to catch security issues pre-deploy.1164. **Hardcoded account/region** — `account: '123456789'` in construct code. Use `cdk.json` context or `cdk.Environment` lookup for portability.1175. **No snapshot tests** — CDK generates CloudFormation templates that change unexpectedly. Add `expect(template).toMatchSnapshot()` tests to detect unintended changes.118119## Quality Checklist120121```122[ ] Stacks separated: stateful (data) vs stateless (compute)123[ ] L2/L3 constructs used (not raw CloudFormation L1)124[ ] cdk-nag enabled with AwsSolutions pack125[ ] Snapshot tests for all stacks126[ ] CDK Pipelines for self-mutating CI/CD127[ ] Least privilege IAM via grant methods (grantRead, grantWrite)128[ ] cdk synth produces valid CloudFormation129[ ] Cross-stack references use exported outputs130[ ] Removal policies set (RETAIN for production data, DESTROY for dev)131[ ] Tags applied via Aspects for cost allocation132[ ] cdk diff reviewed before every deployment133[ ] Lambda functions use Powertools for observability134```