Customizable CDK TypeScript project template that decouples application development from pipeline integration. The structure allows developers to build and test AWS applications without the overhead of a CI/CD pipeline. When ready for pipeline integration, the transition is as easy as uncommenting code and redefining deployment stages.
.
├── README.md
├── bin
│ ├── app.ts # Develop the app with no pipeline
│ └── pipeline.ts # Pipeline to deploy the app (disabled by default)
├── cdk.json # Update the app entry point to bin/pipeline.ts to enable pipeline
├── config.json # App specific configuration
├── jest.config.js
├── lib
│ ├── app # App modules go here
│ ├── app-stack.ts
│ ├── app-stage.ts # Pipeline app stage (disabled by default)
│ └── pipeline-stack.ts # Pipeline stack (disabled by default)
├── package.json
├── .gitignore # Comment or uncomment the appropriate lines to avoid committing secrets
├── test
│ └── app.test.ts
└── tsconfig.json- Make sure you have bootstrapped the account you are deploying to with
cdk bootstrap
- Clone the repository and remove the
.gitdirectory:rm -rf .git - Update
.envwith the appropriate values forCDK_DEFAULT_ACCOUNTandCDK_DEFAULT_REGION - Update
config.jsonwith the appropriate values forcdk_appapp_namegithub_personal_access_token_secret_arntags.org,tags.app
- Develop your application in
lib/app-stack.ts, modules inlib/app/and deploy frombin/app.ts - When ready to deploy the pipeline, update
config.jsonwith the appropriate values forcdk_pipelineorganizationrepository_ownerrepository_nameaccount_idfor thebuildanddeploymentenvironments, and the productionaccount_idunder theproductionfield
- Follow the steps in CDK Pipeline Deployments to enable the pipeline
- Add your stage definition to
lib/app-stage.tsand declare them inlib/pipeline-stack.ts - Push your code to the
mainbranch - Deploy the pipeline with
cdk deploy
The app requires the following environment variables to be set.
# .env
CDK_DEFAULT_ACCOUNT=<account-id>
CDK_DEFAULT_REGION=<region>Copy the .env.example file to .env and update the values.
The pipeline is disabled by default. To enable it, follow the steps.
- Uncomment the Pipeline modules in .gitignore
- Uncomment bin/pipeline.ts
- Uncomment lib/app-stage.ts and lib/pipeline-stack.ts
- Change the line in cdk.json from
"app": "npx ts-node --prefer-ts-exts bin/app.ts"to"app": "npx ts-node --prefer-ts-exts bin/pipeline.ts"// change this: { "app": "npx ts-node --prefer-ts-exts bin/pipeline.ts", ... } // to this: { "app": "npx ts-node --prefer-ts-exts bin/app.ts", ... }
- Finally, edit the appropriate lines in package.json
{ "name": "app", // Change the name of the app "version": "0.1.0", "bin": { "app": "bin/app.js" // change the key to the name of the app } } - Make sure imports and resource configurations are correct before running
cdk difforcdk deploy - If using tests, make sure to update the test files to reflect the changes
cdk deploydeploy this stack to your default AWS account/regioncdk diffcompare deployed stack with current statecdk synthemits the synthesized CloudFormation template