Borislav Hadzhiev
Wed Apr 13 2022·2 min read
Photo by Andreas Dress
Updated - Wed Apr 13 2022
The CDK deploy command deploys our CDK stack(s) as CloudFormation template(s).
The syntax of the command looks like:
npx aws-cdk deploy
When deploying more than one stack, it's better to explicitly specify the stack names:
npx aws-cdk deploy \ my-stack-dev \ my-stack-prod
CDK is just an abstraction level above CloudFormation. The whole idea behind CDK
is to improve developer experience by allowing us to use a programming language,
rather than a configuration language like json
or yaml
.
Our CDK code eventually gets compiled down to CloudFormation code before a deployment is ran.
When we call the cdk deploy
command a couple of things happen behind the
scenes:
The cdk synth
command is called. It runs our CDK app and synthesizes a
CloudFormation template in the cdk.out
directory:
The cdk.out
directory contains our asset files and the CloudFormation
template. An example of asset files would be the code required for a Lambda
function:
We can look at the cdk.out
directory as a preparation step before
deployment.
cdk bootstrap
command.We only have to run cdk bootstrap
once per environment (account and region)
and it provisions a CloudFormation stack, called CDKToolkit
.
The CDKToolkit
stack consists of an S3 bucket that stores our asset files:
If we have our environment bootstrapped the CDK CLI then deploys our asset files to the S3 bucket:
After our assets are globally available via an S3 bucket our CloudFormation template is deployed / updated.
The cdk deploy
command generates and then deploys the CloudFormation
equivalent of our CDK code.
Note that it's not necessary to run the cdk synth
command before we run
cdk deploy
, because the CDK CLI will automatically synthesize a CloudFormation
template for each stack before deployment.