Bootstrapping
The AWS CDK requires some resources to be provisioned before deploying stacks into an account (i.e. IAM Roles, S3 Bucket for Assets). This is referred to as bootstrapping.
DDK Bootstrap Cases
The following are possible ways of bootstrapping an AWS account for DDK apps.
Default
If no configuration is provided the DDK stacks will leverage the default resources provisioned by cdk bootstrap.
Use Configurator()
See Configurator for more details on the construct.
Schema
Configurator supports the following schema, at both the global and environment level, for defining bootstrap resources for your CDK app.
All fields are optional
bootstrapprefix: (The prefix of role names created to be used in a stack’s synthesizer)qualifier: (The qualifier used to bootstrap this stack)file_assets_bucket_name: (File assets bucket name)stack_version_ssm_parameter: (Default bootstrap stack version SSM parameter)deploy_role: (Default deploy role ARN)file_publish_role: (Default asset publishing role ARN for file (S3) assets)cfn_execution_role: (Default CloudFormation role ARN)lookup_role: (Default lookup role ARN for missing values)
Configurator uses the DefaultStackSynthesizer construct under the hood
Example
"environments": {
"dev": {
"account": "000000000000",
"region": "us-west-2",
"bootstrap": {
"qualifier": "abcdefgh",
"bucket_name": "ddk-abcdefgh-assets-000000000000-us-west-2",
"deploy_role": "arn:aws:iam::000000000000:role/ddk-abcdefgh--deploy-role-000000000000-us-west-2",
"cfn_execution_role":
"arn:aws:iam::000000000000:role/ddk-abcdefgh-cfn-exec-role-000000000000-us-west-2",
"file_publish_role":
"arn:aws:iam::000000000000:role/ddk-abcdefgh-file-publishing-role-000000000000-us-west-2",
"lookup_role": "arn:aws:iam::000000000000:role/ddk-abcdefgh-lookup-role-000000000000-us-west-2",
}
}
}
The stack synthesizer will be created for your app using all values specified in Configurator() and resort to default cdk bootstrap values when not explicitly set.
Note: The values for account and region will be default to CDK_DEFAULT_ACCOUNT and CDK_DEFAULT_REGION if not explicitly set in the environment config.
Using Legacy DDK Bootstrap Roles
If you are familiar with the <1.0.0 versions of the DDK there was a separate package including a CLI with a ddk bootstrap -e ${ENVIRONMENT_ID} command. This builds a bootstrap stack with slightly modified resources as compared to CDK’s native bootstrap method. Let’s look at an example of using existing DDK bootstrap roles with newer versions of the DDK core library.
- Assume we have deployed a DDK bootstrap stack for a
devenvironment in our account.
- Configure
ddk.jsonwith the prefix:ddkto indicate any stacks created within this environment should use ddk bootstrap roles.{ "environments": { "dev": { "bootstrap": { "prefix": "ddk" } } } } - Use BaseStack with the
devenvironment passed as a property.
-
import * as cdk from "aws-cdk-lib"; import { BaseStack } from "aws-ddk-core"; const app = new cdk.App(); const stack = new BaseStack(app, 'ExampleStack', {environmentId: "dev"}) console.log(stack.synthesizer) -
import aws_cdk as cdk from aws_ddk_core import BaseStack app = cdk.App() stack = BaseStack(app, "ExampleStack", environment_id: "dev") print(stack.synthesizer) app.synth()