The CDK Toolkit (CLI) - Common Commands
The cdk
command-line interface is used to interact with your CDK apps.
-
cdk init
: Initializes a new CDK project in a specified language. -
cdk synth
: Synthesizes the CDK code into a CloudFormation template. This is useful for inspection before deployment. -
cdk bootstrap
: Deploys the "CDK Toolkit" stack into an AWS environment. This stack contains resources the CDK needs to deploy your apps, such as an S3 bucket for storing assets. This only needs to be run once per environment. -
cdk deploy
: Deploys your stack(s) to the specified AWS environment. -
cdk diff
: Compares the current deployed version of your stack with the version defined in your code and displays the differences. -
cdk destroy
: Destroys the deployed stack(s) and their associated resources.
Key Files and Directories
-
cdk.out/
: This directory contains the output of thecdk synth
command, including the generated CloudFormation templates and any file assets. -
cdk.context.json
: This file caches context values retrieved from your AWS environment, such as Availability Zones or AMI IDs, so that your synthesized templates are stable.
Advantages of Using AWS CDK
-
Use Familiar Languages: Define infrastructure in TypeScript, JavaScript, Python, Java, C#, or Go.
-
Higher-Level Abstraction: Constructs allow you to define complex infrastructure with less code and focus on your application's architecture rather than the minute details of resource configuration.
-
Infrastructure as Code (IaC): Enables best practices like version control, code reviews, and automated testing for your infrastructure.
-
Easier CI/CD Integration: The CDK integrates smoothly with CI/CD tools like AWS CodePipeline and CodeBuild to automate your deployment pipelines.
Pricing
-
The AWS CDK framework itself is free to use.
-
You are only billed for the AWS resources (e.g., EC2 instances, S3 buckets, Lambda functions) that you provision with your CDK applications, just as if you had created them manually.