Class: Awful::Ssm

Inherits:
Cli 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



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/awful/ssm.rb', line 59

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.output 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



48
49
50
51
52
53
54
# File 'lib/awful/ssm.rb', line 48

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

#lsObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/awful/ssm.rb', line 28

def ls
  ssm.list_commands.commands.output 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



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/awful/ssm.rb', line 78

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]
    }
  ).output do |response|
    puts response.command.command_id
  end
end