Getting Started with AWS CDK with Python¶
AWS CDK¶
Notes on getting started creating a new CDK app Adding commands and information that I find important as I go through creating new cdk apps in python
$ mkdir newapp && cd newapp
$ cdk init app --language python
$ python3 -m venv .venv
$ source .venv/bin/activate
$ pip install -r requirements.txt
Useful commands cdk ls list all stacks in the app cdk synth emits the synthesized CloudFormation template cdk deploy deploy this stack to your default AWS account/region cdk diff compare deployed stack with current state cdk docs open CDK documentation
Bootstrapping an account¶
Bootstrapping - AWS Docs
An environment needs to be bootstrapped if any of the following apply.
- An AWS CDK stack being deployed uses Assets.
- An AWS CloudFormation template generated by the app exceeds 50 kilobytes.
- One or more of the stacks uses the DefaultSynthesizer. We will explain stack synthesizers in more detail shortly, but in brief, the DefaultSynthesizer is used if you have set the @aws-cdk/core:newStyleStackSynthesis feature flag in your app’s cdk.json or if you explicitly create a DefaultSynthesizer and pass it to your stack. CDK Pipelines use the DefaultSynthesizer, so if your app uses CDK Pipelines, you must bootstrap the environments you will deploy into as well as the environment that contains the pipeline.
Important: You may incur AWS charges for data stored in the bootstrapped resources.
Note: Older versions of the modern template created a Customer Master Key (CMK) in each bootstrapped environment by default. To avoid charges for the CMK, re-bootstrap these environments using –no-bootstrap-customer-key. The current default is to not use a CMK to avoid these charges.
To bootstrap with the modern template (Not enabled by default) add this environment variable:
$ export CDK_NEW_BOOTSTRAP=1
$ cdk bootstrap