Apps

The main artifact of an AWS CDK program is called a CDK App. This is an executable program that can be used to synthesize deployment artifacts that can be deployed by supporting tools like the AWS CDK Toolkit, which are described in AWS CDK Tools.

Tools interact with apps through the program’s argv/stdout interface, which can be easily implemented using the App class, as shown in the following example.

import { App } from '@aws-cdk/cdk'

const app = new App(process.argv); // input: ARGV

// <add stacks here>

process.stdout.write(app.run());

An Stack is a collection of Stack objects, as shown in the following example.

import { App } from '@aws-cdk/cdk'
import { MyStack } from './my-stack'

const app = new App(process.argv);

const dev = new MyStack(app, { name: 'Dev', region: 'us-west-2', dev: true })
const preProd = new MyStack(app, { name: 'PreProd', region: 'us-west-2', preProd: true })
const prod = [
    new MyStack(app, { name: 'NAEast', region: 'us-east-1' }),
    new MyStack(app, { name: 'NAWest', region: 'us-west-2' }),
    new MyStack(app, { name: 'EU', region: 'eu-west-1', encryptedStorage: true })
]

new DeploymentPipeline(app, {
    region: 'us-east-1',
    strategy: DeploymentStrategy.Waved,
    preProdStages: [ preProd ],
    prodStages: prod
});

process.stdout.write(app.run());

Use the AWS CDK Toolkit to list the stacks in this executable, as shown in the following example.

cdk list
[
   { name: "Dev", region: "us-west-2" }
   { name: "PreProd", region: "us-west-2" },
   { name: "NAEast", region: "us-east-1" },
   { name: "NAWest", region: "us-west-2" },
   { name: "EU", region: "eu-west-1" },
   { name: "DeploymentPipeline", region: 'us-east-1' }
]

Or deploy one of the stacks, as shown in the following example.

cdk deploy Dev
...