This is the AWS CDK v2 Developer Guide. The older CDK v1 entered maintenance on June 1, 2022 and ended support on June 1, 2023.
An AWS Cloud Development Kit (AWS CDK) project represents the files and folders that contain your CDK code. Contents will vary based on your programming language.
You can create your AWS CDK project manually or with the AWS CDK Command Line Interface (AWS CDK CLI)
cdk init
command. In this topic, we will refer to the project structure and naming conventions of files and
folders created by the AWS CDK CLI. You can customize and organize your CDK projects to fit your needs.
Note
Project structure created by the AWS CDK CLI may vary across versions over time.
Universal files and folders
- .git
-
If you have
git
installed, the AWS CDK CLI automatically initializes a Git repository for your project. The.git
directory contains information about the repository. - .gitignore
-
Text file used by Git to specify files and folders to ignore.
- README.md
-
Text file that provides you with basic guidance and important information for managing your AWS CDK project. Modify this file as necessary to document important information regarding your CDK project.
- cdk.json
-
Configuration file for the AWS CDK. This file provides instruction to the AWS CDK CLI regarding how to run your app.
Language-specific files and folders
The following files and folders are unique to each supported programming language.
The following is an example project created in the my-cdk-ts-project
directory using the
cdk init --language typescript
command:
my-cdk-ts-project ├── .git ├── .gitignore ├── .npmignore ├── README.md ├── bin │ └── my-cdk-ts-project.ts ├── cdk.json ├── jest.config.js ├── lib │ └── my-cdk-ts-project-stack.ts ├── node_modules ├── package-lock.json ├── package.json ├── test │ └── my-cdk-ts-project.test.ts └── tsconfig.json
- .npmignore
-
File that specifies which files and folders to ignore when publishing a package to the npm registry. This file is similar to
.gitignore
, but is specific to npm packages. - bin/my-cdk-ts-project.ts
-
The application file defines your CDK app. CDK projects can contain one or more application files. Application files are stored in the
bin
folder.The following is an example of a basic application file that defines a CDK app:
#!/usr/bin/env node import 'source-map-support/register'; import * as cdk from 'aws-cdk-lib'; import { MyCdkTsProjectStack } from '../lib/my-cdk-ts-project-stack'; const app = new cdk.App(); new MyCdkTsProjectStack(app, 'MyCdkTsProjectStack');
- jest.config.js
-
Configuration file for Jest. Jest is a popular JavaScript testing framework.
- lib/my-cdk-ts-project-stack.ts
-
The stack file defines your CDK stack. Within your stack, you define AWS resources and properties using constructs.
The following is an example of a basic stack file that defines a CDK stack:
import * as cdk from 'aws-cdk-lib'; import { Construct } from 'constructs'; export class MyCdkTsProjectStack extends cdk.Stack { constructor(scope: Construct, id: string, props?: cdk.StackProps) { super(scope, id, props); // code that defines your resources and properties go here } }
- node_modules
-
Common folder in Node.js projects that contain dependencies for your project.
- package-lock.json
-
Metadata file that works with the
package.json
file to manage versions of dependencies. - package.json
-
Metadata file that is commonly used in Node.js projects. This file contains information about your CDK project such as the project name, script definitions, dependencies, and other import project-level information.
- test/my-cdk-ts-project.test.ts
-
A test folder is created to organize tests for your CDK project. A sample test file is also created.
You can write tests in TypeScript and use Jest to compile your TypeScript code before running tests.
- tsconfig.json
-
Configuration file used in TypeScript projects that specifies compiler options and project settings.