CDK App Project¶
The CDK App Project type provides an opinionated setup for creating AWS CDK applications with best practices and common configurations pre-configured.
Overview¶
This project type extends the standard AwsCdkTypeScriptApp from projen with additional features:
- Prettier configuration with sensible defaults
- VSCode settings and extensions for enhanced development experience
- Common project structure and tooling setup
- Configurable options that respect user preferences
- CDK app-specific setup with sample application code
Quick Start¶
To create a new CDK App project, use the projen CLI:
This command will create a new project with the CDK App template and prompt you for the required configuration options such as:
- Project name
- CDK version
- Default branch
After the project is created, you can customize it further by editing the .projenrc.ts file:
| .projenrc.ts | |
|---|---|
Highlighted lines explanation:
- Line 4: Choose a descriptive name for your CDK application
- Line 6: Pin to a specific CDK version for consistency
- Line 10: Enable prettier formatting (default: true)
- Line 11: Enable VSCode workspace configuration (default: true)
Features¶
Common Configurations¶
This project type includes the same common configurations as other project types:
Default Configurations
For complete details about Prettier and VSCode configurations, see Default Configurations. This includes:
- Prettier Configuration - Code formatting rules and customization
- VSCode Configuration - Editor settings and recommended extensions
CDK App Structure¶
The CDK App project creates a complete application structure with:
- Main application entry point (
src/main.ts) - CDK configuration (
cdk.json) - Sample stack (optional via
sampleCodeoption) - Deployment scripts and configuration
- Proper TypeScript setup for CDK apps
Configuration Options¶
Basic Configuration¶
All standard AwsCdkTypeScriptAppOptions are supported. Here are the most common options:
| Basic CDK App Configuration | |
|---|---|
Common Configuration Options¶
For Prettier and VSCode configuration options, refer to Default Configurations:
- Prettier: Customization Guide
- VSCode: Configuration Options
Sample Code Configuration¶
Enable/Disable Sample Code¶
Behavior Matrix¶
prettier |
vscode |
sampleCode |
Prettier Files | VSCode Files | Sample App Code |
|---|---|---|---|---|---|
undefined |
undefined |
undefined |
✅ Created | ✅ Created | ✅ Generated |
true |
true |
true |
✅ Created | ✅ Created | ✅ Generated |
false |
true |
false |
❌ Not created | ✅ Created | ❌ No sample |
true |
false |
true |
✅ Created | ❌ Not created | ✅ Generated |
false |
false |
false |
❌ Not created | ❌ Not created | ❌ No sample |
Examples¶
Minimal Setup¶
Perfect for getting started quickly with all defaults:
| .projenrc.ts - Minimal Setup | |
|---|---|
Customized Setup¶
Example with custom prettier settings and disabled sample code:
Highlighted lines explanation:
- Lines 8-13: Custom prettier settings for longer lines and 4-space indentation
- Line 16: Enable VSCode configuration explicitly
- Line 19: Disable sample code generation for a clean starting point
Production Setup¶
Optimized for production deployments:
Highlighted lines explanation:
- Line 9: No sample code for production applications
- Lines 10-11: Keep development tools enabled
- Lines 14-17: CDK feature flags for production deployments
Project Structure¶
After running yarn projen with a CDK App project, you'll get the following structure:
my-cdk-app/
├── .github/
│ └── workflows/ # CI/CD workflows
│ ├── build.yml
│ └── upgrade-main.yml
├── .vscode/ # VSCode configuration (if enabled)
│ ├── extensions.json # Recommended extensions
│ └── settings.json # Editor settings
├── src/
│ └── main.ts # Application entry point (if sampleCode enabled)
├── test/
│ └── *.test.ts # Test files
├── .eslintrc.json # ESLint configuration
├── .gitignore # Git ignore rules
├── .prettierrc.json # Prettier config (if enabled)
├── .projenrc.ts # Projen configuration
├── cdk.json # CDK configuration
├── package.json # NPM package configuration
├── tsconfig.json # TypeScript configuration
└── README.md # Generated README
Conditional Files
Some files are only created based on your configuration:
.vscode/folder: Only whenvscode: true(default).prettierrc.json: Only whenprettier: true(default)src/main.ts: Only whensampleCode: true(default)
Deployment¶
Local Development¶
For local development and testing:
CI/CD Pipeline¶
The generated GitHub Actions workflows provide automated:
- Build and test on pull requests
- Dependency updates with automated PRs
- Security scanning with automated vulnerability detection
CDK Commands¶
Common CDK commands you'll use:
Best Practices¶
1. Use Consistent Configurations¶
Stick with the default prettier and VSCode configurations unless you have specific requirements. This ensures consistency across your team and projects.
2. Pin CDK Version¶
Always specify a specific CDK version to ensure consistent builds:
cdkVersion: '2.1.0', // Good - specific version
// cdkVersion: '^2.0.0', // Avoid - could lead to inconsistencies
3. Environment-Specific Configuration¶
Use CDK context for environment-specific settings:
4. Leverage Sample Code for Learning¶
Keep sampleCode: true when learning CDK or starting new projects. Disable it for production applications.
5. Use Feature Flags¶
Enable CDK feature flags for better functionality:
context: {
'@aws-cdk/core:enableStackNameDuplicates': true,
'@aws-cdk/core:stackRelativeExports': true,
},
Troubleshooting¶
CDK Commands Not Working¶
If CDK commands fail:
- Ensure AWS credentials are configured (
aws configure) - Verify CDK is installed globally (
npm install -g aws-cdk) - Bootstrap your AWS environment (
npx cdk bootstrap)
Prettier Not Working¶
If prettier isn't formatting your code:
- Ensure the prettier extension is installed in VSCode
- Check that
"editor.defaultFormatter": "esbenp.prettier-vscode"is in your VSCode settings - Verify
.prettierrc.jsonexists in your project root
Build Errors¶
If you encounter build errors:
- Run
yarn installto ensure all dependencies are installed - Run
yarn projento regenerate configuration files - Check TypeScript errors with
yarn build
Deployment Issues¶
Common deployment problems:
- Missing permissions: Ensure your AWS credentials have sufficient permissions
- Resource conflicts: Use unique resource names across environments
- Stack limits: AWS has limits on resources per stack
Migration Guide¶
From Standard AwsCdkTypeScriptApp¶
To migrate from a standard AwsCdkTypeScriptApp to CdkApp:
- Install the package:
npm install @jttc/projen-project-types - Update your
.projenrc.ts:
- import { AwsCdkTypeScriptApp } from 'projen/lib/awscdk';
+ import { CdkApp } from '@jttc/projen-project-types';
- const project = new AwsCdkTypeScriptApp({
+ const project = new CdkApp({
// ... same options
});
- Run
yarn projento regenerate files - Commit the changes
The migration is backward compatible - all existing options will continue to work.
Advanced Configuration¶
Custom CDK Context¶
Configure CDK behavior with context values:
Additional Dependencies¶
Add commonly used CDK modules:
Contributing¶
To contribute improvements to the CDK App project type:
- Fork the repository
- Make your changes
- Add tests for new functionality
- Update documentation
- Submit a pull request
Support¶
If you encounter issues or have questions:
- Check this documentation
- Review existing GitHub issues
- Create a new issue with detailed information
- Tag the maintainers for urgent issues
This project type is maintained by Jump to the Cloud team.