LinuxCommandLibrary

cdk

Deploy AWS infrastructure using code

TLDR

List the stacks in the app

$ cdk ls
copy

Synthesize and print the CloudFormation template for the specified stack(s)
$ cdk synth [stack_name]
copy

Deploy one or more stacks
$ cdk deploy [stack_name1 stack_name2 ...]
copy

Destroy one or more stacks
$ cdk destroy [stack_name1 stack_name2 ...]
copy

Compare the specified stack with the deployed stack or a local CloudFormation template
$ cdk diff [stack_name]
copy

Create a new CDK project in the current directory for a specified language
$ cdk init [[-l|--language]] [language]
copy

Open the CDK API reference in your browser
$ cdk docs
copy

SYNOPSIS

cdk <command> [<options>] [<args>]

PARAMETERS

--app <APP>
    Path to CDK app entrypoint (default: infers from package.json or cdk.json)

-o, --output <DIR>
    Output directory for synthesized assets (default: cdk.out)

--context <KEY=VAL>
    Set context key-value pairs passed to the app

--json
    Output results in JSON format

-v, --verbose [LEVEL]
    Increase verbosity (0-8, default 1)

--profile <NAME>
    Use specific AWS profile from credentials file

--region <REGION>
    AWS region (overrides config)

--version
    Display version information

-h, --help
    Show help for command

bootstrap
    Deploy CDK bootstrap stack for asset staging

deploy [<STACK> ...]
    Deploy specified stacks or all

synth [<STACK> ...]
    Synthesize CloudFormation templates

destroy [<STACK> ...]
    Destroy stacks (requires confirmation)

diff [<STACK>]
    Compare deployed and current stack states

ls [-l]
    List stacks in app (long format with -l)

DESCRIPTION

The cdk command is the command-line interface for the AWS Cloud Development Kit (CDK), an open-source framework for defining cloud infrastructure in code using familiar programming languages like TypeScript, Python, JavaScript, Java, C#, and Go.

CDK apps are synthesized into AWS CloudFormation templates, which can then be deployed to provision resources. The CLI handles key operations such as synthesizing templates (synth), deploying stacks (deploy), comparing changes (diff), listing stacks (ls), bootstrapping environments (bootstrap), and destroying resources (destroy).

It supports multi-account, multi-region deployments and integrates seamlessly with AWS services. Developers write high-level constructs, and CDK translates them into CloudFormation. Requires Node.js and AWS credentials configured via AWS CLI or environment variables.

Common workflow: cdk init to start a project, code the app, cdk synth to generate templates, and cdk deploy to provision.

CAVEATS

Requires Node.js >=14.15.0, AWS CLI configured with credentials. Not suitable for production without proper IAM roles. Large apps may hit CloudFormation limits. Always review diffs before deploy.

INSTALLATION

Install globally via npm: npm install -g aws-cdk. Upgrade with npm upgrade -g aws-cdk.

COMMON WORKFLOW

mkdir my-app && cd my-app && cdk init app --language typescript
cdk synth
cdk bootstrap
cdk deploy

DOCUMENTATION

Full docs at https://docs.aws.amazon.com/cdk. Run cdk help for subcommand details.

HISTORY

Announced by AWS in December 2018, CDK v1 GA in June 2019. CLI evolved with support for new languages. v2 released December 2021 for monorepo efficiency and better performance. Actively maintained by AWS and community.

SEE ALSO

aws(1), node(1), npm(1), cfn-lint(1)

Copied to clipboard