To begin with CDK, we need to understand the following fundamentals:
The main sub-commands of CDK toolkit (aka AWS CDK CLI or cdk
):
cdk init
: Create a new AWS CDK TypeScript projectcdk bootstrap
: Deploys the CDK toolkit stack into an AWS environmentcdk synth
: Synthesizes and prints the CloudFormation template for this stackcdk deploy
: Deploys the CDK stack(s) into your AWS accountThe two main components of a CDK project:
bin
directory: contains the CDK code for the CDK app.lib
directory: contains the CDK code for the stacks and used constructs.The main workflow when you works with a CDK project:
You update CDK code -> You run cdk deploy
-> cdk synth
is run -> CloudFormation template is “synthesized” -> Resources are deployed to AWS.
Next, we will deploy an example CDK project to understand how everything works.