diff --git a/packages/aws-cdk/README.md b/packages/aws-cdk/README.md index 7a4695cf8280c..e6fc465932013 100644 --- a/packages/aws-cdk/README.md +++ b/packages/aws-cdk/README.md @@ -227,6 +227,33 @@ Example `outputs.json` after deployment of multiple stacks } ``` +##### Deployment Progress + +By default, stack deployment events are displayed as a progress bar with the events for the resource +currently being deployed. + +Set the `--progress` flag to request the complete history which includes all CloudFormation events +```console +$ cdk deploy --progress events +``` + +Alternatively, the `progress` key can be specified in the project config (`cdk.json`). + +The following shows a sample `cdk.json` where the `progress` key is set to *events*. +When `cdk deploy` is executed, deployment events will include the complete history. +``` +{ + "app": "npx ts-node bin/myproject.ts", + "context": { + "@aws-cdk/core:enableStackNameDuplicates": "true", + "aws-cdk:enableDiffNoFail": "true", + "@aws-cdk/core:stackRelativeExports": "true" + }, + "progress": "events" +} +``` +The `progress` key can also be specified as a user setting (`~/.cdk.json`) + #### `cdk destroy` Deletes a stack from it's environment. This will cause the resources in the stack to be destroyed (unless they were configured with a `DeletionPolicy` of `Retain`). During the stack destruction, the command will output progress diff --git a/packages/aws-cdk/bin/cdk.ts b/packages/aws-cdk/bin/cdk.ts index 016a0855494be..d1b0418a86c4a 100644 --- a/packages/aws-cdk/bin/cdk.ts +++ b/packages/aws-cdk/bin/cdk.ts @@ -10,6 +10,7 @@ import { SdkProvider } from '../lib/api/aws-auth'; import { CloudFormationDeployments } from '../lib/api/cloudformation-deployments'; import { CloudExecutable } from '../lib/api/cxapp/cloud-executable'; import { execProgram } from '../lib/api/cxapp/exec'; +import { StackActivityProgress } from '../lib/api/util/cloudformation/stack-activity-monitor'; import { CdkToolkit } from '../lib/cdk-toolkit'; import { RequireApproval } from '../lib/diff'; import { availableInitLanguages, cliInit, printAvailableTemplates } from '../lib/init'; @@ -89,7 +90,8 @@ async function parseCommandLineArguments() { .option('force', { alias: 'f', type: 'boolean', desc: 'Always deploy stack even if templates are identical', default: false }) .option('parameters', { type: 'array', desc: 'Additional parameters passed to CloudFormation at deploy time (STACK:KEY=VALUE)', nargs: 1, requiresArg: true, default: {} }) .option('outputs-file', { type: 'string', alias: 'O', desc: 'Path to file where stack outputs will be written as JSON', requiresArg: true }) - .option('previous-parameters', { type: 'boolean', default: true, desc: 'Use previous values for existing parameters (you must specify all parameters on every deployment if this is disabled)' }), + .option('previous-parameters', { type: 'boolean', default: true, desc: 'Use previous values for existing parameters (you must specify all parameters on every deployment if this is disabled)' }) + .option('progress', { type: 'string', choices: [StackActivityProgress.BAR, StackActivityProgress.EVENTS], desc: 'Display mode for stack activity events.' }), ) .command('destroy [STACKS..]', 'Destroy the stack(s) named STACKS', yargs => yargs .option('exclusively', { type: 'boolean', alias: 'e', desc: 'Only destroy requested stacks, don\'t include dependees' }) @@ -279,6 +281,7 @@ async function initCommandLine() { parameters: parameterMap, usePreviousParameters: args['previous-parameters'], outputsFile: args.outputsFile, + progress: configuration.settings.get(['progress']), ci: args.ci, }); diff --git a/packages/aws-cdk/lib/api/cloudformation-deployments.ts b/packages/aws-cdk/lib/api/cloudformation-deployments.ts index dac91e4b9e5e6..8b21203ec2a7e 100644 --- a/packages/aws-cdk/lib/api/cloudformation-deployments.ts +++ b/packages/aws-cdk/lib/api/cloudformation-deployments.ts @@ -7,6 +7,7 @@ import { Mode, SdkProvider } from './aws-auth'; import { deployStack, DeployStackResult, destroyStack } from './deploy-stack'; import { ToolkitInfo } from './toolkit-info'; import { CloudFormationStack, Template } from './util/cloudformation'; +import { StackActivityProgress } from './util/cloudformation/stack-activity-monitor'; export interface DeployStackOptions { /** @@ -89,6 +90,14 @@ export interface DeployStackOptions { */ usePreviousParameters?: boolean; + /** + * Display mode for stack deployment progress. + * + * @default - StackActivityProgress.Bar - stack events will be displayed for + * the resource currently being deployed. + */ + progress?: StackActivityProgress; + /** * Whether we are on a CI system * @@ -163,6 +172,7 @@ export class CloudFormationDeployments { force: options.force, parameters: options.parameters, usePreviousParameters: options.usePreviousParameters, + progress: options.progress, ci: options.ci, }); } diff --git a/packages/aws-cdk/lib/api/deploy-stack.ts b/packages/aws-cdk/lib/api/deploy-stack.ts index 6fab563802bd3..51f6b7aa11ec4 100644 --- a/packages/aws-cdk/lib/api/deploy-stack.ts +++ b/packages/aws-cdk/lib/api/deploy-stack.ts @@ -11,7 +11,7 @@ import { contentHash } from '../util/content-hash'; import { ISDK, SdkProvider } from './aws-auth'; import { ToolkitInfo } from './toolkit-info'; import { changeSetHasNoChanges, CloudFormationStack, StackParameters, TemplateParameters, waitForChangeSet, waitForStackDeploy, waitForStackDelete } from './util/cloudformation'; -import { StackActivityMonitor } from './util/cloudformation/stack-activity-monitor'; +import { StackActivityMonitor, StackActivityProgress } from './util/cloudformation/stack-activity-monitor'; // We need to map regions to domain suffixes, and the SDK already has a function to do this. // It's not part of the public API, but it's also unlikely to go away. @@ -153,6 +153,14 @@ export interface DeployStackOptions { */ usePreviousParameters?: boolean; + /** + * Display mode for stack deployment progress. + * + * @default StackActivityProgress.Bar stack events will be displayed for + * the resource currently being deployed. + */ + progress?: StackActivityProgress; + /** * Deploy even if the deployed template is identical to the one we are about to deploy. * @default false @@ -267,6 +275,7 @@ export async function deployStack(options: DeployStackOptions): Promise