Class: RenderCFN::LoadBalancer

Inherits:
AwsObject show all
Defined in:
lib/renderCFN/loadBalancer.rb,
lib/renderCFN/applicationLoadBalancerV2.rb

Instance Method Summary collapse

Methods inherited from AwsObject

#get, #name

Constructor Details

#initialize(arguments) ⇒ LoadBalancer

name, lbPort, instancePort, idleTimeout = 60)



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/renderCFN/loadBalancer.rb', line 5

def initialize( arguments) #name, lbPort, instancePort, idleTimeout = 60)
  @idleTimeout = arguments[:idleTimeout] or 60
  @name = "#{arguments[:name]}ElasticLoadBalancer"
  @awsObject = { 
    @name => {
      'Type' => 'AWS::ElasticLoadBalancing::LoadBalancer', 
      'Properties' => {
        'SecurityGroups' => [],
        'Scheme' => arguments[:scheme] || 'internal',
        'CrossZone' => true,
        'ConnectionSettings' => {
          'IdleTimeout' => @idleTimeout
        },
        'ConnectionDrainingPolicy' => { 'Enabled' => true, 'Timeout' => 60 },
        'Subnets' => arguments[:subnetList], 
        'Tags' => [
          { 'Key' => 'application', 'Value' => arguments[:serviceTitle] },
          { 'Key' => 'StackName', 'Value' => @@stackName },
        ],
        'HealthCheck' => {
          'Target' => "HTTP:#{arguments[:instancePort]}/status-check",
          'Interval' => 6,
          'Timeout' => 5,
          'UnhealthyThreshold' => 2,
          'HealthyThreshold' => 2,
        },
        'Listeners' => [
          {
            'Protocol' => 'HTTP', 
            'LoadBalancerPort' => 80, 
            'InstancePort' => arguments[:instancePort]
          },
          #{
          #  'Protocol' => 'HTTP', 
          #  'LoadBalancerPort' => 9876, 
          #  'InstancePort' => 9876
          #}
        ]
      }
    }
  }
  if arguments[:lbPort] != 80
    @awsObject[@name]['Properties']['Listeners'].push (
        {
          'Protocol' => 'HTTP', 
          'LoadBalancerPort' => arguments[:lbPort], 
          'InstancePort' => arguments[:instancePort]
        }
    )
  end

end

Instance Method Details

#addListener(lbPort, instancePort) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/renderCFN/loadBalancer.rb', line 66

def addListener( lbPort, instancePort)
  @awsObject[@name]['Properties']['Listeners'].push (
    {
      'Protocol' => 'HTTP', 
      'LoadBalancerPort' => lbPort, 
      'InstancePort' => instancePort
    }
  )
end

#addSecurityGroup(securityGroup) ⇒ Object



62
63
64
# File 'lib/renderCFN/loadBalancer.rb', line 62

def addSecurityGroup( securityGroup)
  @awsObject[@name]['Properties']['SecurityGroups'].push( {'Ref' => "#{securityGroup}"} )
end

#addSslListener(lbPort, instancePort, certificate) ⇒ Object



76
77
78
79
80
81
82
83
84
85
# File 'lib/renderCFN/loadBalancer.rb', line 76

def addSslListener( lbPort, instancePort, certificate)
  @awsObject[@name]['Properties']['Listeners'].push (
    {
      'Protocol' => 'HTTPS', 
      'LoadBalancerPort' => lbPort, 
      'InstancePort' => instancePort,
      'SSLCertificateId' => certificate
    }
  )
end

#createLoadBalancerObject



65
66
67
68
69
# File 'lib/renderCFN/applicationLoadBalancerV2.rb', line 65

def createLoadBalancer()
  # create load balancer via sdk
  # store load balancer ARN for use when attaching listeners
  # How to get it to associate with the stack so it's deleted on stack deletion?
end

#modifyHealthCheck(newHealthCheck) ⇒ Object



58
59
60
# File 'lib/renderCFN/loadBalancer.rb', line 58

def modifyHealthCheck( newHealthCheck)
  @awsObject[@name]['Properties']['HealthCheck']['Target'] = newHealthCheck
end