How to use CDK init to create a CDK App


Borislav Hadzhiev

Fri Apr 16 20212 min read

Creating a new CDK App #

In order to create a new CDK App we have to use the cdk init command. For example:

mkdir cdk-app cd cdk-app npx cdk init app --language=typescript
Note - In order to use the CDK CLI - you have to have the CDK CLI installed and the AWS CLI installed and configured.

We can write our CDK code in many programming languages and init our CDK app from multiple starter templates, to list the available options we can append the --list flag to the command:

npx cdk init --list

The output shows all the available programming languages we can use in our CDK app and all of the available starter templates:

available languages

There are 3 templates we can start from:

  • app - a basic starter template
  • lib - a template for writing a CDK construct library
  • sample-app - a starter with some constructs included

Note that cdk init cannot be run in a non-empty directory, so we first have to create one:

mkdir cdk-app cd cdk-app npx cdk init app --language=typescript

The output from the command looks like:

cdk init output

At this point we have successfully initialized an empty CDK project.

If you want to specify an AWS CLI profile, other than your default one to be used as the default environment for your CDK App, you can pass the --profile flag, i.e.:

mkdir cdk-app cd cdk-app npx cdk init app \ --language=typescript \ --profile=my-profile

Further Reading #

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee