diff --git a/README.md b/README.md index 3985c94..409051e 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,19 @@ 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. + +Will prompt for confirmation. + +``` +Note + This will only work on a stack that are in the `UPDATE_IN_PROGRESS` state. +``` + ### 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 +}