From e99182921f33dfc4c5c2b09e986f4068fc63f296 Mon Sep 17 00:00:00 2001 From: Bill Hegazy Date: Thu, 1 Jun 2017 14:49:54 +0800 Subject: [PATCH 1/2] add cancel command and docs --- README.md | 7 +++++ src/commands/cancelUpdateStack.js | 52 +++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/commands/cancelUpdateStack.js diff --git a/README.md b/README.md index 3985c94..f45f98a 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,13 @@ Requires a stack name, `--file`, and `--parameters`. [![asciicast](https://asciinema.org/a/7e745ao7yz9v1kmubmf57vyfr.png)](https://asciinema.org/a/7e745ao7yz9v1kmubmf57vyfr) +### cancel + +Cancels an update on the specified stack. The stack rolls back the update and reverts to the previous stack configuration. + +Requires a stack name, `--file`, and `--parameters`. + + ### delete Deletes an existing stack. diff --git a/src/commands/cancelUpdateStack.js b/src/commands/cancelUpdateStack.js new file mode 100644 index 0000000..5c5b1c7 --- /dev/null +++ b/src/commands/cancelUpdateStack.js @@ -0,0 +1,52 @@ +import inquirer from 'inquirer' + +function cancelUpdateStack (cloudformation, argv, utils) { + const stackName = argv._[1] + + inquirer.prompt([ + { + type: 'confirm', + name: 'ok', + message: `Are you sure you want to cancel an update on ${stackName}?` + } + ], function (answers) { + if (!answers.ok) { + return process.exit() + } + + const beforeCancelDate = new Date() + + cloudformation.cancelUpdateStack({ + StackName: stackName + }, function (err, response) { + if (err) { + throw new Error(err) + } + + utils.pollEvents(stackName, 'Canceling...', [ + [ 'LogicalResourceId', stackName ], + [ 'ResourceStatus', 'CANCEL_COMPLETE' ] + ], function (err) { + if (err) { + if (err.code !== 'ValidationError') { + throw new Error(err) + } + process.exit() + } + + console.log(` ${stackName} update has been canceled...`.cyan) + + process.exit() + }, { + startDate: beforeCancelDate, + ignoreMissing: true + }) + }) + }) +} + +export default { + name: 'cancel', + description: 'Cancels an update on the specified stack', + fn: cancelUpdateStack +} From e2e667a8ce9ea992754614e21092675ec881dd56 Mon Sep 17 00:00:00 2001 From: Bill Hegazy Date: Thu, 1 Jun 2017 14:56:52 +0800 Subject: [PATCH 2/2] fix docs and add more details --- README.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f45f98a..409051e 100644 --- a/README.md +++ b/README.md @@ -72,8 +72,14 @@ Requires a stack name, `--file`, and `--parameters`. Cancels an update on the specified stack. The stack rolls back the update and reverts to the previous stack configuration. -Requires a stack name, `--file`, and `--parameters`. +Requires a stack name. + +Will prompt for confirmation. +``` +Note + This will only work on a stack that are in the `UPDATE_IN_PROGRESS` state. +``` ### delete