CDK Bootstrap refers to the process of deploying a CloudFormation stack, called the CDKToolkit, into an AWS environment. This stack provides the resources needed for the AWS Cloud Development Kit (CDK) to deploy applications into that environment.
Understanding CDK Bootstrap
The CDK needs certain resources in your AWS environment before you can start deploying applications. These resources are provisioned by the cdk bootstrap
command. Let's break down what this means:
-
cdk bootstrap
command: This command is your starting point. It prepares your AWS environment for CDK deployments. -
CDKToolkit CloudFormation stack: The
cdk bootstrap
command deploys a CloudFormation stack namedCDKToolkit
. This stack contains the necessary infrastructure components for the CDK. -
Environment: This refers to a specific combination of your AWS account and region (e.g.,
123456789012/us-east-1
). You need to bootstrap each environment where you plan to deploy CDK applications. -
S3 Bucket: A key component of the
CDKToolkit
stack is an S3 bucket. This bucket is used to store synthesized templates (the CloudFormation templates generated by the CDK) and related assets (like Lambda function code or Docker images) before they are deployed. The docs on AWS CDK boostrapping state of thecdk bootstrap
command:cdk bootstrap Deploys a CDKToolkit CloudFormation stack into the specified environment(s), that provides an S3 bucket that cdk deploy will use to store synthesized templates and the related assets, before triggering a CloudFormation stack update.
Why is CDK Bootstrap Necessary?
The CDK needs a place to store the resources required for deploying your application. The CDKToolkit
stack, specifically the S3 bucket it provides, serves this purpose. Without bootstrapping, the CDK will not be able to deploy your infrastructure.
When to Use CDK Bootstrap
- First-time CDK user: If you are new to the CDK and haven't deployed anything using it before, you absolutely need to run
cdk bootstrap
. - New AWS environment: When you want to deploy CDK applications to a new AWS account and/or region, you need to bootstrap that specific environment.
- Upgrading CDK version: Sometimes, newer versions of the CDK CLI require you to re-bootstrap your environments to update the
CDKToolkit
stack with the latest features and capabilities.
Practical Insights
- You can specify the environment to bootstrap using the
--profile
(AWS CLI profile),--region
(AWS region), and--account
(AWS account ID) flags. For example:cdk bootstrap --profile my-aws-profile --region us-west-2
. - It's a good practice to bootstrap each AWS account and region combination where you intend to deploy CDK applications, even if you don't plan to deploy there immediately. This saves time later.
Example
Imagine you want to deploy an application to the us-east-1
region in your AWS account 123456789012
. You would run the following command:
cdk bootstrap aws://123456789012/us-east-1
This command would deploy the CDKToolkit
stack to the us-east-1
region within the specified AWS account.