'Purpose and scope of AWS CDK bootstrap stack?

The docs on AWS CDK boostrapping state of the cdk 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. The name of the deployed stack can be configured using the --toolkit-stack-name argument.

$ # Deploys to all environments
$ cdk bootstrap --app='node bin/main.js'

$ # Deploys only to environments foo and bar
$ cdk bootstrap --app='node bin/main.js' foo bar

However, how often does CDK need to be bootstrapped? Is it:

  • once for each AWS account?
  • once for each application in each AWS account?
  • once for each application in each AWS account that requires assets?
  • something else?


Solution 1:[1]

background:

cdk bootstrap is a tool in the AWS CDK command-line interface responsible for populating a given environment (that is, a combination of AWS account and region) with resources required by the CDK to perform deployments into that environment.

When you run cdk bootstrap cdk deploys the CDK toolkit stack into an AWS environment.

The bootstrap command creates a CloudFormation stack in the environment passed on the command line. Currently, the only resource in that stack is An S3 bucket that holds the file assets and the resulting CloudFormation template to deploy.

cdk bootstrap command is running one time per account/ region.

Simple scenario to sum-up:

  1. Run cdk bootstrap - create a new s3 bucket, IAM roles, etc.
  2. Run cdk deploy - to deploy your stack for the first time, new template added to bootstrap s3 bucket.
  3. Apply any change to cdk stack.
  4. Run cdk diff - to view differences -

Behind the scenes, CDK generates the new template and compare it with the CDK template that exists in the bootstrap bucket.

More about cdk bootstrap.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1