cdk
Deploy AWS infrastructure using code
TLDR
List the stacks in the app
Synthesize and print the CloudFormation template for the specified stack(s)
Deploy one or more stacks
Destroy one or more stacks
Compare the specified stack with the deployed stack or a local CloudFormation template
Create a new CDK project in the current directory for a specified language
Open the CDK API reference in your browser
SYNOPSIS
cdk [options] <command> [arguments]
PARAMETERS
--version
Shows the version of the AWS CDK CLI and exiting.
--verbose, -v
Shows verbose logging output during command execution.
--debug
Enables debugging output, including stack traces for errors.
--json
Emits output in JSON format, useful for programmatic consumption.
--context <key=value>
Passes arbitrary context values to the CDK application. Can be specified multiple times.
--strict
Enables strict mode, causing the CDK to fail on warnings during synthesis.
--app <command>
Specifies the command-line program to execute to generate the CDK application (e.g., 'npx ts-node bin/my-app.ts').
--output <path>
Sets the output directory for synthesized CloudFormation templates.
--no-color
Disables colored output.
DESCRIPTION
The cdk command-line interface (CLI) is the primary tool for interacting with the AWS Cloud Development Kit (CDK). It's important to note that cdk is not a standard, pre-installed Linux command; rather, it's a Node.js-based application typically installed via npm or yarn, primarily used for managing AWS cloud resources.
The AWS CDK is a software development framework for defining your cloud application resources using familiar programming languages. It synthesizes a CloudFormation template, which AWS CloudFormation then deploys. The cdk CLI allows developers to synthesize, deploy, diff, and destroy cloud infrastructure stacks defined in languages like TypeScript, Python, Java, C#, and Go.
It enables developers to use high-level constructs, which are pre-built, reusable components that encapsulate AWS best practices. This approach significantly speeds up cloud infrastructure development, making it more manageable and less prone to errors compared to writing raw CloudFormation templates.
CAVEATS
The cdk command is not part of the standard Linux utility set. It requires Node.js and npm (or yarn) to be installed on the system to be used. It is primarily designed for interacting with AWS cloud resources and requires valid AWS credentials and an AWS account to deploy infrastructure. While a powerful tool for infrastructure as code, its utility is limited to AWS and ecosystems that integrate with AWS CloudFormation.
COMMON COMMANDS
Beyond the global options, the cdk CLI provides several subcommands for different operations:
- cdk synth: Synthesizes the CDK application into a CloudFormation template.
- cdk deploy [stack-name]: Deploys a specified stack (or all stacks) to your AWS account.
- cdk diff [stack-name]: Compares the deployed stack with the current local definition.
- cdk destroy [stack-name]: Destroys a specified stack and its resources.
- cdk bootstrap: Deploys the CDK Toolkit staging resources (e.g., S3 bucket, IAM roles) into an AWS environment.
- cdk ls: Lists all stacks defined in your CDK application.
- cdk init: Initializes a new CDK project from a template.
INSTALLATION
The cdk CLI is typically installed globally using npm (Node Package Manager) or yarn:npm install -g aws-cdk
oryarn global add aws-cdk
This makes the cdk command available in your system's PATH.
HISTORY
The AWS Cloud Development Kit (CDK) was initially launched as a developer preview in July 2018 and became generally available in July 2019. Developed by Amazon Web Services, it quickly gained traction in the infrastructure as code (IaC) space by allowing developers to define cloud resources using general-purpose programming languages. Its development aimed to address the complexities of managing cloud infrastructure through declarative templates, offering a more programmatic and object-oriented approach. It has seen continuous development and new features added with regular releases, becoming a key tool for many AWS users.