How to use CDK init to create a CDK App


Borislav Hadzhiev

Thu Apr 14 20222 min read

Updated - Thu Apr 14 2022

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 aws-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 aws-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 aws-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 aws-cdk init app \ --language=typescript \ --profile=my-profile

Further Reading #

Use the search field on my Home Page to filter through my more than 1,000 articles.