Class: Laws::AWS::ECSHelper

Inherits:
BaseHelper show all
Defined in:
lib/laws/aws/ecs_helper.rb

Instance Method Summary collapse

Constructor Details

#initializeECSHelper

Returns a new instance of ECSHelper.



6
7
8
9
10
# File 'lib/laws/aws/ecs_helper.rb', line 6

def initialize
  super
  @ecs_client = Aws::ECS::Client.new
  @prompt = TTY::Prompt.new
end

Instance Method Details

#create_task_choices(tasks) ⇒ Object



52
53
54
55
56
57
58
59
# File 'lib/laws/aws/ecs_helper.rb', line 52

def create_task_choices(tasks)
  tasks.map do |task|
    task_id = task.task_arn.split('/').last
    task_def = task.task_definition_arn.split('/').last
    display = "#{task_id} (#{task_def})"
    { name: display, value: task }
  end
end

#get_container_names(task) ⇒ Object



48
49
50
# File 'lib/laws/aws/ecs_helper.rb', line 48

def get_container_names(task)
  task.containers.map(&:name)
end

#list_clustersObject



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/laws/aws/ecs_helper.rb', line 12

def list_clusters
  clusters = []
  next_token = nil

  loop do
    response = @ecs_client.list_clusters(next_token: next_token)
    clusters.concat(response.cluster_arns.map { |arn| arn.split('/').last })
    next_token = response.next_token
    break unless next_token
  end

  clusters
end

#list_tasks(cluster_name) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/laws/aws/ecs_helper.rb', line 26

def list_tasks(cluster_name)
  tasks = []
  next_token = nil

  loop do
    response = @ecs_client.list_tasks(cluster: cluster_name, next_token: next_token)

    unless response.task_arns.empty?
      task_details = @ecs_client.describe_tasks(
        cluster: cluster_name,
        tasks: response.task_arns
      )
      tasks.concat(task_details.tasks)
    end

    next_token = response.next_token
    break unless next_token
  end

  tasks
end