Class: Lono::Cfn::Cancel

Inherits:
Object
  • Object
show all
Includes:
AwsServices, Util
Defined in:
lib/lono/cfn/cancel.rb

Instance Method Summary collapse

Methods included from Util

#are_you_sure?, #switch_current

Methods included from AwsServices

#cfn, #ec2, #iam, #s3, #s3_presigner, #s3_resource, #sts

Methods included from AwsServices::Util

#find_stack, #rollback_complete?, #stack_exists?, #testing_update?

Constructor Details

#initialize(stack_name, options = {}) ⇒ Cancel

Returns a new instance of Cancel.



6
7
8
9
# File 'lib/lono/cfn/cancel.rb', line 6

def initialize(stack_name, options={})
  @stack_name = switch_current(stack_name)
  @options = options
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/lono/cfn/cancel.rb', line 11

def run
  stack = find_stack(@stack_name)
  unless stack
    puts "The '#{@stack_name}' stack does not exist. Unable to cancel"
    exit 1
  end

  puts "Canceling updates to #{@stack_name}."
  puts "Current stack status: #{stack.stack_status}"
  if stack.stack_status == "CREATE_IN_PROGRESS"
    cfn.delete_stack(stack_name: @stack_name)
    puts "Canceling stack creation."
  elsif stack.stack_status == "UPDATE_IN_PROGRESS"
    cfn.cancel_update_stack(stack_name: @stack_name)
    puts "Canceling stack update."
    status.wait if @options[:wait]
  else
    puts "The stack is not in a state to that is cancelable: #{stack.stack_status}"
  end
end

#statusObject



32
33
34
# File 'lib/lono/cfn/cancel.rb', line 32

def status
  @status ||= Status.new(@stack_name)
end