AWS CDK Cheat Sheet

# Create needed AWS resources for CDK environment:

$ cdk bootstrap
# Project (app) is created using cli:

$ cdk init <app|lib|sample-app> --language=<language>

$ cdk init app --language=typescript

$ cdk init --list
Available templates:
* app: Template for a CDK Application
   └─ cdk init app --language=[csharp|fsharp|go|java|javascript|python|typescript]
* lib: Template for a CDK Construct Library
   └─ cdk init lib --language=typescript
* sample-app: Example CDK Application with some constructs
   └─ cdk init sample-app --language=[csharp|fsharp|java|javascript|python|typescript]
# Compile typescript to js

$ npm run build

# Watch for changes and compile
$ npm run watch

# Perform the jest unit tests
$ npm run test

# Creates the cdk.out directory and generate CloudFormation template (in JSON), the assets, other meta data

$ cdk synth


# Generate CloudFormation in YAML format:
$ cdk synth --no-staging > cdk.out/Stack.template.yaml
# Templates are launched by CloudFormation or CDK stacks are deployed:

$ cdk deploy

# using a specific profile
$ cdk deploy --profile PROFILE_NAME

# deploy a specific stack
$ cdk deploy STACK_NAME

# deploy multiple stacks
$ cdk deploy STACK_1 STACK_2

# deploy all stackes in the app
$ cdk deploy "*"
# List the stacks in the CDK app:

$ cdk list
# Delete the stack:

$ cdk destroy
# Compare local and deployed stack:

$ cdk diff
Check for problem:

$ cdk doctor
# Open https://docs.aws.amazon.com/cdk/api/latest/

$ cdk docs

Documentation

Best Practices

Examples

github.com/kolomied/awesome-cdk

Some Gotchas

When synthesizing an AWS CDK stack, I get the message --app is required either in command-line, in cdk.json or in ~/.cdk.json

This message usually means that you aren’t in the main directory of your AWS CDK project when you issue cdk synth. The file cdk.json in this directory, created by the cdk init command, contains the command line needed to run (and thereby synthesize) your AWS CDK app. For a TypeScript app, for example, the default cdk.json looks something like this:

{
  "app": "npx ts-node bin/my-cdk-app.ts"
}

Also see: docs.aws.amazon.com/cdk/latest/guide/troubleshooting.html#troubleshooting_app_required

Leave a Comment

Your email address will not be published.

one × 5 =