Module: Ufo::AwsServices::Concerns

Extended by:
Memoist
Included in:
Ufo::AwsServices
Defined in:
lib/ufo/aws_services/concerns.rb

Instance Method Summary collapse

Instance Method Details

#find_stack(stack_name) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ufo/aws_services/concerns.rb', line 7

def find_stack(stack_name)
  resp = cfn.describe_stacks(stack_name: stack_name)
  resp.stacks.first
rescue Aws::CloudFormation::Errors::ValidationError => e
  # example: Stack with id demo-web does not exist
  if e.message =~ /Stack with/ && e.message =~ /does not exist/
    nil
  else
    raise
  end
end

#find_stack_resources(stack_name) ⇒ Object



44
45
46
47
48
49
50
51
52
53
# File 'lib/ufo/aws_services/concerns.rb', line 44

def find_stack_resources(stack_name)
  resp = cfn.describe_stack_resources(stack_name: stack_name)
  resp.stack_resources
rescue Aws::CloudFormation::Errors::ValidationError => e
  if e.message.include?("does not exist")
    nil
  else
    raise
  end
end

#stack_resources(stack_name) ⇒ Object



19
20
21
22
23
24
# File 'lib/ufo/aws_services/concerns.rb', line 19

def stack_resources(stack_name)
  resp = cfn.describe_stack_resources(stack_name: stack_name)
  resp.stack_resources
rescue Aws::CloudFormation::Errors::ValidationError => e
  e.message.include?("does not exist") ? return : raise
end

#statusObject



39
40
41
# File 'lib/ufo/aws_services/concerns.rb', line 39

def status
  CfnStatus.new(@stack_name) # NOTE: @stack_name must be set in the including Class
end

#task_definition_arns(family, max_items = 10) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ufo/aws_services/concerns.rb', line 26

def task_definition_arns(family, max_items=10)
  resp = ecs.list_task_definitions(
    family_prefix: family,
    sort: "DESC",
  )
  arns = resp.task_definition_arns
  arns = arns.select do |arn|
    task_definition = arn.split('/').last.split(':').first
    task_definition == family
  end
  arns[0..max_items]
end