Class: Awful::Ssm

Inherits:
Cli
  • Object
show all
Defined in:
lib/awful/ssm.rb

Constant Summary collapse

COLORS =
{
  Success:   :green,
  TimedOut:  :red,
  Cancelled: :red,
  Failed:    :red
}

Instance Method Summary collapse

Methods inherited from Cli

#initialize

Constructor Details

This class inherits a constructor from Awful::Cli

Instance Method Details

#documents(name = '.') ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/awful/ssm.rb', line 55

def documents(name = '.')
  filter = [{key: 'PlatformTypes', value: options[:platform_types].capitalize}]
  ssm.list_documents(document_filter_list: filter).document_identifiers.select do |doc|
    doc.name.match(/#{name}/i)
  end.tap do |docs|
    if options[:long]
      print_table docs.map { |d| [d.name, d.platform_types.join(',')] }
    else
      puts docs.map(&:name)
    end
  end
end

#dump(id) ⇒ Object



44
45
46
47
48
49
50
# File 'lib/awful/ssm.rb', line 44

def dump(id)
  ssm.list_command_invocations(command_id: id, details: true).command_invocations.tap do |cmds|
    cmds.each do |cmd|
      puts YAML.dump(stringify_keys(cmd.to_hash))
    end
  end
end

#lsObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/awful/ssm.rb', line 24

def ls
  ssm.list_commands.commands.tap do |cmds|
    if options[:long]
      print_table cmds.map { |c|
        [
          c.command_id,
          c.instance_ids.join(','),
          c.document_name,
          color(c.status),
          c.requested_date_time,
          c.comment
        ]
      }
    else
      puts cmds.map(&:command_id)
    end
  end
end

#shell_script(*instance_ids) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/awful/ssm.rb', line 74

def shell_script(*instance_ids)
  ssm.send_command(
    instance_ids: instance_ids,
    comment: options[:comment],
    timeout_seconds: options[:timeout],
    output_s3_bucket_name: options[:bucket],
    output_s3_key_prefix: options[:prefix],
    document_name: 'AWS-RunShellScript',
    parameters: {
      commands: options[:commands]
    }
  ).tap do |response|
    puts response.command.command_id
  end
end