class Awry::Cfn

Constants

COLORS
STATUSES

stack statuses that are not DELETE_COMPLETE

Public Instance Methods

client() click to toggle source
# File lib/awry/cfn.rb, line 33
def client
  @_client ||= Aws::CloudFormation::Client.new
end
delete(name) click to toggle source
# File lib/awry/cfn.rb, line 83
def delete(name)
  if yes?("Really delete stack #{name}?", :yellow)
    client.delete_stack(stack_name: name)
  end
end
events(name) click to toggle source
# File lib/awry/cfn.rb, line 91
def events(name)
  events = client.describe_stack_events(stack_name: name).map(&:stack_events).flatten
  events = events.first(options[:number]) if options[:number]
  events.map do |e|
    [ e.timestamp, color(e.resource_status), e.resource_type, e.logical_resource_id, e.resource_status_reason ]
  end.tap do |list|
    print_table list.reverse
  end
end
limits() click to toggle source
# File lib/awry/cfn.rb, line 102
def limits
  client.describe_account_limits.account_limits.map do |l|
    [l.name, l.value]
  end.tap do |list|
    print_table list.sort
  end
end
ls(prefix = nil) click to toggle source
# File lib/awry/cfn.rb, line 39
def ls(prefix = nil)
  client.list_stacks(stack_status_filter: STATUSES).map(&:stack_summaries).flatten.tap do |stacks|
    stacks.select! { |s| s.stack_name.start_with?(prefix) } if prefix
  end.map do |s|
    [s.stack_name, s.creation_time, color(s.stack_status), s.template_description]
  end.tap do |list|
    print_table list.sort
  end
end
outputs(name) click to toggle source
# File lib/awry/cfn.rb, line 59
def outputs(name)
  client.describe_stacks(stack_name: name).stacks.first.outputs.each_with_object({}) do |o, hash|
    hash[o.output_key] = o.output_value
  end.tap do |hash|
    print_table hash.sort
  end
end
parameters(name) click to toggle source
# File lib/awry/cfn.rb, line 50
def parameters(name)
  client.describe_stacks(stack_name: name).stacks.first.parameters.each_with_object({}) do |p, h|
    h[p.parameter_key] = p.parameter_value
  end.tap do |hash|
    print_table hash.sort
  end
end
resources(name) click to toggle source
# File lib/awry/cfn.rb, line 69
def resources(name)
  client.list_stack_resources(stack_name: name).map(&:stack_resource_summaries).flatten.tap do |resources|
    if options[:match]
      regexp = Regexp.new(options[:match], Regexp::IGNORECASE)
      resources.select! { |r| regexp.match(r.resource_type) }
    end
  end.map do |r|
    [ r.logical_resource_id, r.resource_type, color(r.resource_status), r.physical_resource_id ]
  end.tap do |list|
    print_table list.sort
  end
end