What does CDK Bootstrap do

What is CDK bootstrap #

CDK bootstrap is a command we can access using the

The cdk bootstrap command provisions a CloudFormation stack called CDKToolkit.
This CloudFormation stack is specific to the environment (region and account)
our CDK stack is configured for.

Every CDK application belongs to a specific environment.

An environment consists of an account number and a region, where the CDK app is
going to be deployed.

We set the environment for a CDK project when instantiating a CDK stack:

const app = new cdk.App();

const myStack = new MyCdkStack(app, 'my-cdk-stack', {
  stackName: `my-cdk-stack`,
  env: {
    region: process.env.CDK_DEFAULT_REGION,
    account: process.env.CDK_DEFAULT_ACCOUNT,

The initialization process of the environment consists of:

  • provisioning an S3 bucket, where our assets (i.e. Lambda function code,
    CloudFormation template) will be stored
  • provisioning IAM roles the CDK CLI needs in order to perform a deployment in
    the environment In order to deploy to multiple environments we have to
    bootstrap each environment.

The CDKToolkit stack provisions an S3 bucket that stores the assets(i.e.
Lambda code, CloudFormation template, etc), required for a CDK deployment.

cdk toolkit stack

In the S3 bucket we will have an assets « directory »:

assets directory

The assets directory is going to contain our zipped file assets:

zipped file assets

For a simple CDK project with a single lambda function, my file assets consist
of the index.js handler code for the Lambda.

Using CDK bootstrap #

In order to bootstrap our default account and region we can run the
cdk bootstrap command.

We only need to use the bootstrap command once for every environment(region
and account).

If we use the command more than once, the
CDK CLI will check if our
CDKToolkit stack has to be updated. If necessary, the stack will be updated.
If not, running the bootstrap command does nothing.

We can also specify other environments to bootstrap:

npx aws-cdk bootstrap --profile my-profile

npx aws-cdk bootstrap ACCOUNT_NUMBER/REGION

npx aws-cdk bootstrap 123456789/us-east-1

Conclusion #

The CDK bootstrap command provisions a CloudFormation stack called CDKToolkit.

The stack consists of an S3 bucket that stores file assets (i.e. Lambda
function code, CloudFormation templates), required for deployments

We have to bootstrap each environment (account and region) separately.

Further Reading #

Source link

Laisser un commentaire