<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Leigh Hayward on Medium]]></title>
        <description><![CDATA[Stories by Leigh Hayward on Medium]]></description>
        <link>https://medium.com/@leigh.hayward1?source=rss-e888225cbd9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hjCADSsezN30dCLAuKSYLg.jpeg</url>
            <title>Stories by Leigh Hayward on Medium</title>
            <link>https://medium.com/@leigh.hayward1?source=rss-e888225cbd9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 23:19:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leigh.hayward1/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Terraform and AWS Application Load Balancers]]></title>
            <link>https://medium.com/@leigh.hayward1/terraform-and-aws-application-load-balancers-62a6f8592bcf?source=rss-e888225cbd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/62a6f8592bcf</guid>
            <category><![CDATA[terraform]]></category>
            <category><![CDATA[alb]]></category>
            <category><![CDATA[application-load-balancer]]></category>
            <category><![CDATA[aws]]></category>
            <dc:creator><![CDATA[Leigh Hayward]]></dc:creator>
            <pubDate>Tue, 02 Jan 2018 16:41:16 GMT</pubDate>
            <atom:updated>2018-01-02T16:50:18.813Z</atom:updated>
            <content:encoded><![CDATA[<h3>First off an apology, sorry it has been a whole year since I wrote my last article. I have been a little busy since then, becoming a new dad and a promotion at work meant blogging about my adventures in AWS took a bit of a backseat… Now the very british apologies are out of the way i’ll jump straight in.</h3><p>The last article outlined the basics of Application Load Balancers (ALB) and how you can use these to leverage a decent saving — this saving was significantly increased earlier this year when AWS increase the number of listeners per ALB from 10 to a whopping 50!</p><p>I&#39;ll start out with the architecture diagram of an ALB.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x56Xuknx2fvw-Nn6BVZaYg.png" /><figcaption>AWS ALB Architecture</figcaption></figure><p>As you can see there are a quite few more moving parts when compared with its predecessor the ELB. Let’s look in more detail what each part is and it’s function while throwing out some nice and handy terraform code snippets. The code below is to be used as an example.</p><p><strong>AWS ALB </strong>— This is the top level component in the architecture the ALB handles the incoming traffic, offloads SSL and balances the load — duh…</p><pre>resource &quot;aws_alb&quot; &quot;alb&quot; {  <br>  name            = &quot;${var.alb_name}&quot;  <br>  subnets         = [&quot;${split(&quot;,&quot;,var.alb_subnets)}&quot;]<br>  security_groups = [&quot;${split(&quot;,&quot;, var.alb_security_groups)}&quot;]<br>  internal        = &quot;${var.internal_alb}&quot;  <br>  idle_timeout    = &quot;${var.idle_timeout}&quot;   <br>  tags {    <br>    Name    = &quot;${var.alb_name}&quot;    <br>  }   <br>  access_logs {    <br>    bucket = &quot;${var.s3_bucket}&quot;    <br>    prefix = &quot;ELB-logs&quot;  <br>  }<br>}</pre><p><strong>ALB Listener</strong>. Listeners are assigned a specific port to keep an ear out for incoming traffic they are you can have a maximum of 50 listeners assigned to each load balancer.</p><pre>resource &quot;aws_alb_listener&quot; &quot;alb_listener&quot; {  <br>  load_balancer_arn = &quot;${aws_alb.alb.arn}&quot;  <br>  port              = &quot;${var.alb_listener_port}&quot;  <br>  protocol          = &quot;${var.alb_listener_protocol}&quot;<br>  <br>  default_action {    <br>    target_group_arn = &quot;${aws_alb_target_group.alb_target.arn}&quot;<br>    type             = &quot;forward&quot;  <br>  }<br>}</pre><p><strong>ALB listener rules</strong> — this is where things get pretty nifty! Each listener can have many rules which means we can route traffic to different places based on two conditions; the path and/or the host.</p><pre>resource &quot;aws_alb_listener_rule&quot; &quot;listener_rule&quot; {<br>  depends_on   = [&quot;aws_alb_target_group.alb_target_group&quot;]  <br>  listener_arn = &quot;${aws_alb_listener.alb_listener.arn}&quot;  <br>  priority     = &quot;${var.priority}&quot;   <br>  action {    <br>    type             = &quot;forward&quot;    <br>    target_group_arn = &quot;${aws_alb_target_group.alb_target_group.id}&quot;  <br>  }   <br>  condition {    <br>    field  = &quot;path-pattern&quot;    <br>    values = [&quot;${var.alb_path}&quot;]  <br>  }<br>}</pre><p>Now the listener has some rules we can forward these onto <strong>target groups</strong>. Target groups are essentially the end point of the ALB architecture — When the listener rule matches a pattern for a request it gets forwarded to the correlating target group. The cool thing about target groups is they have a health check that can directly check the health of a path, for example I have an instance that runs 2 tomcat servers foo and bar. I am able to check the health of foo and bar independently, even though they are on the same instance. Nice!</p><pre>resource &quot;aws_alb_target_group&quot; &quot;alb_target_group&quot; {  <br>  name     = &quot;${var.target_group_name}&quot;  <br>  port     = &quot;${var.svc_port}&quot;  <br>  protocol = &quot;HTTP&quot;  <br>  vpc_id   = &quot;${var.vpc_id}&quot;   <br>  tags {    <br>    name = &quot;${var.target_group_name}&quot;    <br>  }   <br>  stickiness {    <br>    type            = &quot;lb_cookie&quot;    <br>    cookie_duration = 1800    <br>    enabled         = &quot;${var.target_group_sticky}&quot;  <br>  }   <br>  health_check {    <br>    healthy_threshold   = 3    <br>    unhealthy_threshold = 10    <br>    timeout             = 5    <br>    interval            = 10    <br>    path                = &quot;${var.target_group_path}&quot;    <br>    port                = &quot;${var.target_group_port}&quot;  <br>  }<br>}</pre><p>Now we have a target group we need to assign something to it. This is done through target group attachments. Two methods here — 1. Autoscaling Group attachment, for all you Chaos Monkey fans, 2. Instance attachment, for those crazy people who are not using ASG’s. But don’t worry I’ll still show you code for both!</p><pre>#Autoscaling Attachment<br>resource &quot;aws_autoscaling_attachment&quot; &quot;svc_asg_external2&quot; {<br>  alb_target_group_arn   = &quot;${aws_alb_target_group.alb_target_group.arn}&quot;<br>  autoscaling_group_name = &quot;${aws_autoscaling_group.svc_asg.id}&quot;<br>}</pre><pre>#Instance Attachment<br>resource &quot;aws_alb_target_group_attachment&quot; &quot;svc_physical_external&quot; {<br>  target_group_arn = &quot;${aws_alb_target_group.alb_target_group.arn}&quot;<br>  target_id        = &quot;${aws_instance.svc.id}&quot;  <br>  port             = 8080<br>}</pre><p>That is pretty much it go forth and make yourself some Application Load Balancers using Hashicorp Terraform.</p><h3>GOTCHAS</h3><p>There are a few gotchas that had me going in circles for a while…</p><ol><li>Health checks — Because the health checks act independently if you are using an ASG inside a Target Group configuring them differently can make it difficult to track down where an issue lies.</li><li>Security Groups — Make sure the ALB has rights to call the application in the target group, otherwise it will always be unhealthy.</li><li>Internal and external — An ALB can have the internal property like the ELB. If you have a service that needs both an internal and external endpoint you will need to add 2 target groups to 2 listener rules on 2 different ALBs.</li><li>Dependencies — I have had to add a few depends_on statements otherwise Terraform got its knickers in a twist and started shouting about cycling… as if getting on a bike is going to help here!</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=62a6f8592bcf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to cut AWS ELB costs by 90% using Application Load Balancers.]]></title>
            <link>https://medium.com/@leigh.hayward1/how-cognitoiq-are-using-application-load-balancers-to-cut-elastic-load-balancing-cost-by-90-78d4e980624b?source=rss-e888225cbd9------2</link>
            <guid isPermaLink="false">https://medium.com/p/78d4e980624b</guid>
            <category><![CDATA[cloud-computing]]></category>
            <category><![CDATA[application-load-balancer]]></category>
            <category><![CDATA[alb]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devops]]></category>
            <dc:creator><![CDATA[Leigh Hayward]]></dc:creator>
            <pubDate>Mon, 23 Jan 2017 16:59:59 GMT</pubDate>
            <atom:updated>2018-01-02T17:12:55.398Z</atom:updated>
            <content:encoded><![CDATA[<p>At CognitoIQ we are running around 50 Elastic Load Balancers (ELBs) per customer environment. On an average day, they will cost us around $34 each, these costs soon mount up, especially as we are now about to launch our 15th environment in the cloud. From this, we could see a massive cost inefficiency with the use of ELBs and so we identified it as an area where we could potentially save a decent amount of money. But what to do….. Application Load Balancers!</p><p>AWS recently launched the Application Load Balancer. It’s like the classic ELB we all know and love but has been administered a hefty dose of Micro Service friendly steroids filling it with heaps of lovely features:</p><p>· Content-Based Routing</p><p>· Containerized Application Support</p><p>· Request Tracing</p><p>· …And so much more</p><p>The feature that struck me was content-based routing. It was one of those beautiful lightbulb moments, we were running apache load balancer in our legacy solution which utilised content based routing. We originally wanted to do something like this in AWS but the thought of not having to manage apache or NginX was far too alluring. It dawned on us that ALBs mean we still have the convenience of Elastic Load Balancing but with included path based routing. The perfect solution.</p><p>ALB are the best of both worlds; I don’t have to manage any additional servers, worry about it being HA or recovery and AWS provide us with content routing.</p><p>I came up with a couple of diagrams illustrating how our ELB infrastructure looks now and how our ALB infrastructure may look moving forward.</p><p>First, here is a simple representation of our current ELB infrastructure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IHOVGPas_j0jju6I5Mq09g.png" /></figure><p>As you can see this is a fairly standard way to waste a lot of money on load balancing… One ELB per service.</p><p>Here is a simplistic representation of an ALB architecture, which will become much more detailed in the next article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rGGHuBKDUJEPJms5lVPT6Q.png" /></figure><p>We have removed the need to have an ELB per service and a route53 record per service. Instead both can now be shared by a single ALB which can forward to multiple services. With this in mind, if we use an ALB to its maximum potential which is 10 rules per load balancer, (or 10 services per ALB), we can turn our 50 load balancer behemoth into a cute little 5 load balancer kitten (because who doesn’t love a kitten?!). Not too shabby!</p><p>Most importantly though, COST.</p><p>Application Load Balancers cost $0.0252 per hour.</p><p>Classic Load Balancers cost $0.028 per hour</p><p>Seems like a no-brainer, right? Not quite, AWS have changed the way they bill on the ALB and have added a new unit, LCU (Load Balancer Capacity Units) which uses the highest values of the following metrics:</p><p>1. New connections (per second)</p><p>2. Active connections (per minute)</p><p>3. Bandwidth (Mbps)</p><p>So, the calculation becomes a little bit more complex… I’ll show you how we worked it through at CognitoIQ.</p><p>Application Load Balancer = $0.0252/h * 24 hours * 5 ALBs = $3.02 per day</p><p>Classic Load Balancer = $0.028 p/h * 24 hours * 50 ELBs = $33.60 per day</p><p>We know that we are going to be using a large amount of bandwidth compared to new and active connections. To work out the cost we took the bandwidth for the account then divided by the number of ELBs. This isn’t an accurate representation for the ELB costs but will derive the cost or load balancing for the account as a whole.</p><p>So, our estimated bandwidth per service is roughly 350 kbp/s which means we can work out our LCU per service:</p><p>350/275 = 1.28618181818 LCU.</p><p>We can then say that with 10 services attached to a single ALB we will be using 13 LCU per hour.</p><p>13 * 0.008 = $0.104 per ALB per hour</p><p>Overall:</p><p>(0.104 + 0.0252) * 24 = $3.10 per day.</p><p>And like I mentioned at the start, for comparison our ELBs cost around $34 a day.</p><p>This is of course all estimation work and obviously is not a complete representation of the cost but gives a good ballpark figure.</p><p>If we scale this out taking a 24/7 runtime:</p><p>ALB = 3.10 * 365 = $1131.5 per year</p><p>ELB = 34 * 365 = $12410 per year</p><p>So yes, for Cognito ALB’s are a no brainer, they cash in at about 1/10th the cost of ELB’s.</p><p>In the next article, I will share a more detailed architecture diagram and terraform code so you can provision your own ALB to start saving money.</p><p>Next Article:</p><p><a href="https://medium.com/cognitoiq/terraform-and-aws-application-load-balancers-62a6f8592bcf">https://medium.com/cognitoiq/terraform-and-aws-application-load-balancers-62a6f8592bcf</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=78d4e980624b" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>