Method: Inf::AWS.launch_load_balancer

Defined in:
lib/aws.rb

.launch_load_balancerObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/aws.rb', line 46

def self.launch_load_balancer
  lb_name = "app-lb-#{app_name}"
  cert = ENV['CERT_ARN']

  listeners = [{
    instance_port: 5000,
    instance_protocol: 'HTTP',
    load_balancer_port: 80,
    protocol: 'HTTP'
  }]

  cert && listeners.push(
    instance_port: 5000,
    instance_protocol: 'HTTP',
    load_balancer_port: 443,
    protocol: 'HTTPS',
    ssl_certificate_id: cert
  )

  lb_dns = elb.create_load_balancer(
    load_balancer_name: lb_name,
    subnets: ENV['SUBNET_IDS'].split(','),
    security_groups: [ENV['ELB_SG']],
    scheme: 'internet-facing',
    listeners: listeners
  ).dns_name

  elb.configure_health_check(
    load_balancer_name: lb_name,
    health_check: {
      target: 'HTTP:5000/health_check',
      interval: 10, # seconds
      timeout: 5, # seconds to respond
      unhealthy_threshold: 2, # two consecutive failures
      healthy_threshold: 2
    }
  )

  put_state("apps/#{app_name}/lb-name", lb_name)
  put_state("apps/#{app_name}/lb-dns", lb_dns)

  puts 'Launched load balancer (or it was running)'.blue
end