0
# AWS CDK Projects
1
2
AWS CDK applications and construct libraries for cloud infrastructure. Provides comprehensive setup for AWS CDK projects across multiple programming languages with infrastructure-as-code best practices.
3
4
## Capabilities
5
6
### AwsCdkTypeScriptApp Class
7
8
AWS CDK application in TypeScript with comprehensive cloud development setup.
9
10
```typescript { .api }
11
/**
12
* AWS CDK application in TypeScript
13
* Provides infrastructure-as-code development with AWS CDK
14
*/
15
class AwsCdkTypeScriptApp extends TypeScriptProject {
16
constructor(options: AwsCdkTypeScriptAppOptions);
17
18
/** CDK version being used */
19
readonly cdkVersion: string;
20
/** AWS constructs library version */
21
readonly constructsVersion: string;
22
/** CDK CLI integration */
23
readonly cdkTask: Task;
24
/** App entry point */
25
readonly appEntrypoint: string;
26
}
27
28
interface AwsCdkTypeScriptAppOptions extends TypeScriptProjectOptions {
29
/** AWS CDK version (default: "2.x") */
30
cdkVersion?: string;
31
/** CDK CLI version */
32
cdkCliVersion?: string;
33
/** Constructs version */
34
constructsVersion?: string;
35
/** CDK application entry point (default: "src/main.ts") */
36
appEntrypoint?: string;
37
/** Additional CDK dependencies */
38
cdkDependencies?: string[];
39
/** Enable CDK integration tests */
40
integrationTests?: boolean;
41
/** CDK context configuration */
42
context?: Record<string, any>;
43
/** Lambda bundling options */
44
lambdaBundling?: boolean;
45
}
46
```
47
48
**TypeScript CDK App Example:**
49
50
```typescript
51
import { AwsCdkTypeScriptApp } from "projen";
52
53
const app = new AwsCdkTypeScriptApp({
54
name: "my-cdk-app",
55
defaultReleaseBranch: "main",
56
57
// CDK configuration
58
cdkVersion: "2.100.0",
59
appEntrypoint: "src/main.ts",
60
61
// CDK dependencies
62
cdkDependencies: [
63
"@aws-cdk/aws-lambda",
64
"@aws-cdk/aws-apigateway",
65
"@aws-cdk/aws-dynamodb",
66
"@aws-cdk/aws-s3",
67
],
68
69
// TypeScript configuration
70
srcdir: "src",
71
testdir: "test",
72
73
// Dependencies
74
deps: [
75
"aws-lambda",
76
"@types/aws-lambda",
77
],
78
devDeps: [
79
"@aws-cdk/assert",
80
],
81
82
// Enable integration tests
83
integrationTests: true,
84
85
// CDK context
86
context: {
87
"@aws-cdk/core:enableStackNameDuplicates": "true",
88
"aws-cdk:enableDiffNoFail": "true",
89
},
90
91
// Lambda bundling
92
lambdaBundling: true,
93
});
94
95
// Add CDK-specific tasks
96
app.addTask("deploy", {
97
description: "Deploy the CDK app",
98
exec: "cdk deploy",
99
});
100
101
app.addTask("diff", {
102
description: "Show deployment diff",
103
exec: "cdk diff",
104
});
105
106
app.addTask("destroy", {
107
description: "Destroy the CDK app",
108
exec: "cdk destroy",
109
});
110
```
111
112
### AwsCdkPythonApp Class
113
114
AWS CDK application in Python with Python-specific CDK tooling.
115
116
```typescript { .api }
117
/**
118
* AWS CDK application in Python
119
* Python-based infrastructure-as-code with AWS CDK
120
*/
121
class AwsCdkPythonApp extends PythonProject {
122
constructor(options: AwsCdkPythonAppOptions);
123
124
/** CDK version being used */
125
readonly cdkVersion: string;
126
/** CDK CLI integration */
127
readonly cdkTask: Task;
128
/** App entry point */
129
readonly appEntrypoint: string;
130
}
131
132
interface AwsCdkPythonAppOptions extends PythonProjectOptions {
133
/** AWS CDK version */
134
cdkVersion?: string;
135
/** CDK CLI version */
136
cdkCliVersion?: string;
137
/** CDK application entry point (default: "app.py") */
138
appEntrypoint?: string;
139
/** Additional CDK dependencies */
140
cdkDependencies?: string[];
141
/** CDK context configuration */
142
context?: Record<string, any>;
143
}
144
```
145
146
**Python CDK App Example:**
147
148
```typescript
149
import { AwsCdkPythonApp } from "projen";
150
151
const app = new AwsCdkPythonApp({
152
name: "my-python-cdk-app",
153
moduleName: "my_python_cdk_app",
154
defaultReleaseBranch: "main",
155
156
// CDK configuration
157
cdkVersion: "2.100.0",
158
appEntrypoint: "app.py",
159
160
// Python version
161
pythonVersion: ">=3.8",
162
163
// CDK dependencies
164
deps: [
165
"aws-cdk-lib>=2.100.0",
166
"constructs>=10.0.0",
167
],
168
devDeps: [
169
"pytest>=7.0.0",
170
"aws-cdk.assertions>=2.100.0",
171
],
172
173
// Use Poetry
174
poetry: true,
175
});
176
```
177
178
### AwsCdkJavaApp Class
179
180
AWS CDK application in Java with Maven build system.
181
182
```typescript { .api }
183
/**
184
* AWS CDK application in Java
185
* Java-based infrastructure-as-code with AWS CDK and Maven
186
*/
187
class AwsCdkJavaApp extends JavaProject {
188
constructor(options: AwsCdkJavaAppOptions);
189
190
/** CDK version being used */
191
readonly cdkVersion: string;
192
/** CDK CLI integration */
193
readonly cdkTask: Task;
194
/** App entry point class */
195
readonly mainClass: string;
196
}
197
198
interface AwsCdkJavaAppOptions extends JavaProjectOptions {
199
/** AWS CDK version */
200
cdkVersion?: string;
201
/** CDK CLI version */
202
cdkCliVersion?: string;
203
/** Main application class */
204
mainClass?: string;
205
/** Additional CDK dependencies */
206
cdkDependencies?: string[];
207
}
208
```
209
210
### AwsCdkConstructLibrary Class
211
212
AWS CDK construct library for publishing reusable infrastructure components.
213
214
```typescript { .api }
215
/**
216
* AWS CDK construct library project
217
* For creating and publishing reusable CDK constructs
218
*/
219
class AwsCdkConstructLibrary extends ConstructLibrary {
220
constructor(options: AwsCdkConstructLibraryOptions);
221
222
/** CDK version being used */
223
readonly cdkVersion: string;
224
/** Construct library configuration */
225
readonly constructsVersion: string;
226
}
227
228
interface AwsCdkConstructLibraryOptions extends ConstructLibraryOptions {
229
/** AWS CDK version */
230
cdkVersion?: string;
231
/** Constructs version */
232
constructsVersion?: string;
233
/** CDK dependencies for the library */
234
cdkDependencies?: string[];
235
/** Enable CDK assertions for testing */
236
cdkAssert?: boolean;
237
/** Integration test configuration */
238
integrationTests?: boolean;
239
}
240
```
241
242
**CDK Construct Library Example:**
243
244
```typescript
245
import { AwsCdkConstructLibrary } from "projen";
246
247
const lib = new AwsCdkConstructLibrary({
248
name: "my-cdk-constructs",
249
defaultReleaseBranch: "main",
250
251
// Library metadata
252
author: "CDK Developer",
253
authorEmail: "cdk@example.com",
254
description: "Reusable CDK constructs for common patterns",
255
256
// CDK configuration
257
cdkVersion: "2.100.0",
258
constructsVersion: "10.0.0",
259
260
// CDK dependencies
261
cdkDependencies: [
262
"@aws-cdk/aws-lambda",
263
"@aws-cdk/aws-apigateway",
264
"@aws-cdk/aws-dynamodb",
265
],
266
267
// Publishing configuration
268
publishToPypi: {
269
distName: "my-cdk-constructs",
270
module: "my_cdk_constructs",
271
},
272
publishToMaven: {
273
javaPackage: "com.example.cdk.constructs",
274
mavenGroupId: "com.example",
275
mavenArtifactId: "cdk-constructs",
276
},
277
publishToNuget: {
278
dotNetNamespace: "Example.Cdk.Constructs",
279
packageId: "Example.Cdk.Constructs",
280
},
281
282
// Enable testing
283
cdkAssert: true,
284
integrationTests: true,
285
});
286
```
287
288
### Lambda Function Integration
289
290
Integrated Lambda function development within CDK projects.
291
292
```typescript { .api }
293
/**
294
* Lambda function construct for CDK projects
295
* Provides integrated Lambda development and deployment
296
*/
297
class LambdaFunction extends Component {
298
constructor(project: AwsCdkTypeScriptApp, options: LambdaFunctionOptions);
299
300
/** Function entry point */
301
readonly entrypoint: string;
302
/** Function handler */
303
readonly handler: string;
304
/** Runtime environment */
305
readonly runtime: string;
306
}
307
308
interface LambdaFunctionOptions {
309
/** Function name */
310
name: string;
311
/** Entry point file */
312
entrypoint: string;
313
/** Handler function */
314
handler?: string;
315
/** Runtime environment */
316
runtime?: string;
317
/** Environment variables */
318
environment?: Record<string, string>;
319
/** Memory allocation */
320
memorySize?: number;
321
/** Timeout in seconds */
322
timeout?: number;
323
/** Enable bundling */
324
bundling?: boolean;
325
}
326
```
327
328
### CDK Integration Tests
329
330
Integration testing framework for CDK applications.
331
332
```typescript { .api }
333
/**
334
* CDK integration testing framework
335
* Provides end-to-end testing for CDK applications
336
*/
337
class IntegrationTest extends Component {
338
constructor(project: AwsCdkTypeScriptApp, options?: IntegrationTestOptions);
339
340
/** Integration test task */
341
readonly testTask: Task;
342
/** Test discovery patterns */
343
readonly testPaths: string[];
344
}
345
346
interface IntegrationTestOptions {
347
/** Test file patterns */
348
testPaths?: string[];
349
/** Test timeout */
350
timeout?: number;
351
/** Test environment */
352
testEnvironment?: Record<string, string>;
353
/** Stack naming pattern */
354
stackNamingScheme?: string;
355
}
356
```
357
358
### AutoDiscover Feature
359
360
Automatic discovery of CDK constructs and stacks.
361
362
```typescript { .api }
363
/**
364
* Automatic discovery of CDK constructs and stacks
365
* Automatically generates CDK code based on file structure
366
*/
367
class AutoDiscover extends Component {
368
constructor(project: AwsCdkTypeScriptApp, options?: AutoDiscoverOptions);
369
}
370
371
interface AutoDiscoverOptions {
372
/** Source directories to discover */
373
srcdir?: string;
374
/** Test directories to discover */
375
testdir?: string;
376
/** Lambda function directories */
377
lambdadir?: string;
378
/** Integration test directories */
379
integdir?: string;
380
}
381
```
382
383
**Complete CDK Application Example:**
384
385
```typescript
386
import { AwsCdkTypeScriptApp } from "projen";
387
388
const app = new AwsCdkTypeScriptApp({
389
name: "comprehensive-cdk-app",
390
defaultReleaseBranch: "main",
391
392
// Project metadata
393
author: "Cloud Engineer",
394
authorEmail: "cloud@example.com",
395
description: "Comprehensive AWS CDK application",
396
397
// CDK configuration
398
cdkVersion: "2.100.0",
399
appEntrypoint: "src/main.ts",
400
401
// CDK dependencies for various AWS services
402
cdkDependencies: [
403
"@aws-cdk/aws-lambda",
404
"@aws-cdk/aws-apigateway",
405
"@aws-cdk/aws-dynamodb",
406
"@aws-cdk/aws-s3",
407
"@aws-cdk/aws-cloudfront",
408
"@aws-cdk/aws-route53",
409
"@aws-cdk/aws-certificatemanager",
410
"@aws-cdk/aws-iam",
411
"@aws-cdk/aws-logs",
412
"@aws-cdk/aws-sns",
413
"@aws-cdk/aws-sqs",
414
],
415
416
// Application dependencies
417
deps: [
418
"aws-lambda",
419
"@types/aws-lambda",
420
"aws-sdk",
421
"@aws-sdk/client-dynamodb",
422
"@aws-sdk/client-s3",
423
],
424
devDeps: [
425
"@aws-cdk/assertions",
426
"aws-cdk-local",
427
],
428
429
// TypeScript configuration
430
srcdir: "src",
431
testdir: "test",
432
libdir: "lib",
433
434
// CDK context for environment-specific settings
435
context: {
436
"@aws-cdk/core:enableStackNameDuplicates": "true",
437
"aws-cdk:enableDiffNoFail": "true",
438
"@aws-cdk/core:stackRelativeExports": "true",
439
},
440
441
// Enable features
442
integrationTests: true,
443
lambdaBundling: true,
444
});
445
446
// Add Lambda functions
447
new LambdaFunction(app, {
448
name: "api-handler",
449
entrypoint: "src/lambda/api-handler.ts",
450
handler: "handler",
451
runtime: "nodejs18.x",
452
environment: {
453
TABLE_NAME: "MyTable",
454
},
455
});
456
457
new LambdaFunction(app, {
458
name: "data-processor",
459
entrypoint: "src/lambda/data-processor.ts",
460
handler: "processData",
461
runtime: "nodejs18.x",
462
memorySize: 512,
463
timeout: 300,
464
});
465
466
// Add CDK tasks
467
app.addTask("deploy:dev", {
468
description: "Deploy to development environment",
469
exec: "cdk deploy --profile dev",
470
});
471
472
app.addTask("deploy:prod", {
473
description: "Deploy to production environment",
474
exec: "cdk deploy --profile prod --require-approval never",
475
});
476
477
app.addTask("synth", {
478
description: "Synthesize CDK templates",
479
exec: "cdk synth",
480
});
481
482
app.addTask("bootstrap", {
483
description: "Bootstrap CDK environment",
484
exec: "cdk bootstrap",
485
});
486
487
app.addTask("local", {
488
description: "Run CDK locally",
489
exec: "cdklocal deploy",
490
});
491
492
// Integration tests
493
app.addTask("test:integration", {
494
description: "Run integration tests",
495
exec: "jest --testPathPattern=test/integration",
496
});
497
498
// Custom package.json fields for CDK
499
app.package.addField("cdk", {
500
version: "2.100.0",
501
app: "npx ts-node src/main.ts",
502
context: {
503
"@aws-cdk/core:enableStackNameDuplicates": "true",
504
},
505
});
506
```
507
508
## Types
509
510
### AWS CDK-Specific Types
511
512
```typescript { .api }
513
interface CdkConfig {
514
/** CDK application entry point */
515
app?: string;
516
/** CDK version */
517
version?: string;
518
/** CDK context */
519
context?: Record<string, any>;
520
/** Feature flags */
521
featureFlags?: Record<string, boolean>;
522
/** Toolkit stack name */
523
toolkitStackName?: string;
524
/** Require approval for deployments */
525
requireApproval?: "never" | "any-change" | "broadening";
526
}
527
528
interface LambdaRuntime {
529
NODEJS_18_X: "nodejs18.x";
530
NODEJS_16_X: "nodejs16.x";
531
PYTHON_3_9: "python3.9";
532
PYTHON_3_8: "python3.8";
533
JAVA_11: "java11";
534
JAVA_8: "java8";
535
DOTNET_6: "dotnet6";
536
GO_1_X: "go1.x";
537
}
538
539
interface StackProps {
540
/** Stack name */
541
stackName?: string;
542
/** Stack description */
543
description?: string;
544
/** Environment (account/region) */
545
env?: {
546
account?: string;
547
region?: string;
548
};
549
/** Tags */
550
tags?: Record<string, string>;
551
/** Termination protection */
552
terminationProtection?: boolean;
553
}
554
```