Skip to content
This repository has been archived by the owner on May 18, 2021. It is now read-only.

Cancel an update on specific stack #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
52 changes: 52 additions & 0 deletions src/commands/cancelUpdateStack.js
Original file line number Diff line number Diff line change
@@ -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
}