AWS CDK Commands and Their Functions - krdheeraj51/aws-labs GitHub Wiki

Key AWS CDK Commands and Their Functions

As you embark on your journey with AWS CDK, it's essential to understand the core commands that facilitate the deployment and management of your applications. Below are the key commands along with their descriptions:

1. cdk bootstrap

  • Purpose: This command installs a bootstrap stack for the first time you deploy an AWS CDK app into an environment or updates an existing bootstrap stack.
  • Usage: It prepares your AWS environment by creating resources required for deploying CDK applications, such as an S3 bucket for storing assets.

2. cdk synth

  • Purpose: Emits the synthesized CloudFormation template in the cdk.out directory.
  • Usage: This command allows you to see what CloudFormation template will be generated from your CDK code. It's useful for verifying that your infrastructure as code is being correctly interpreted by the CDK.

3. cdk diff

  • Purpose: Compares the deployed stack with the current state.
  • Usage: This is a safe way to check what changes will occur when you run cdk deploy. It shows you a detailed comparison between the existing deployed resources and what will be created or modified.

4. cdk deploy

  • Purpose: Deploys the stack to your default AWS account/region.
  • Usage: This command is used as the "build" step for production. It applies all changes defined in your CDK application to your AWS environment, creating or updating resources as needed.

5. cdk deploy --hotswap

  • Purpose: Assesses whether a hotswap deployment can be performed instead of a full CloudFormation deployment.
  • Usage: If possible, this command uses AWS service APIs to directly make changes without going through CloudFormation. However, it falls back to a full CloudFormation deployment if hotswap isn't feasible. Note that this is a one-time operation and should not be used for production deployments.

Summary

Understanding these commands will significantly enhance your ability to manage AWS infrastructure using the CDK. Always remember to use cdk diff before deploying changes to ensure that you are aware of what modifications will take place in your environment. Happy coding!