🚀 DevOps & SRE Certification Program 📅 Starting: 1st of Every Month 🤝 +91 8409492687 🔍 Contact@DevOpsSchool.com

Upgrade & Secure Your Future with DevOps, SRE, DevSecOps, MLOps!

We spend hours on Instagram and YouTube and waste money on coffee and fast food, but won’t spend 30 minutes a day learning skills to boost our careers.
Master in DevOps, SRE, DevSecOps & MLOps!

Learn from Guru Rajesh Kumar and double your salary in just one year.


Get Started Now!

AWS Tutorials: FinOps – AWS ELB Cost optimization strategies

StrategyDescriptionApplicable ELB Types
Use the Right Type of ELBChoose the appropriate load balancer type (ALB, NLB, CLB) based on traffic type and application needs.ALB, NLB, CLB
Right-Size Your Load BalancerUse smaller instance types and pair with Autoscaling groups to avoid overprovisioning.ALB, NLB, CLB
Enable Cross-Zone Load BalancingDistribute traffic evenly across Availability Zones to reduce instance size or number.ALB, NLB
Reduce Idle ELBsIdentify and remove unused ELBs, or consolidate low-traffic ELBs into one.ALB, NLB, CLB
Optimize Listener ConfigurationsReduce the number of listeners and rules; use HTTP/2 to improve performance with fewer connections.ALB
Monitor and Analyze ELB UsageUse AWS Cost Explorer and CloudWatch to track usage and identify inefficiencies.ALB, NLB, CLB
Use AWS Savings Plans or Reserved InstancesCommit to Savings Plans or Reserved Instances for consistent workloads to reduce costs.ALB, NLB, CLB
Leverage Spot InstancesUse Spot Instances with your ELB for significant cost savings if your application can tolerate interruptions.ALB, NLB, CLB
Optimize Traffic RoutingUse geolocation routing with Route 53 or offload static content to a CDN like CloudFront.ALB, NLB, CLB
Review Data Transfer CostsMinimize inter-AZ data transfer to reduce additional charges.ALB, NLB, CLB

This table summarizes cost optimization strategies for AWS Elastic Load Balancers, including the applicable types for each strategy.

Unused AWS Elastic Load Balancers (ELBs) created by Kubernetes cluster,

To locate and clean up unused AWS Elastic Load Balancers (ELBs) created by your Kubernetes cluster, you can follow these steps:

Identify Unused ELBs • Check Kubernetes Annotations:


• Kubernetes typically creates ELBs based on service annotations. You can identify which ELBs are associated with Kubernetes services by inspecting the annotations or tags that Kubernetes applies to the ELBs.
• Use AWS CLI to List ELBs:
• List all ELBs in your AWS account:


    #List all ELBs in your AWS account:
    aws elb describe-load-balancers --query 'LoadBalancerDescriptions[*].[LoadBalancerName,CreatedTime,DNSName]' --output table
    
    # For ALBs and NLBs, use:
    aws elbv2 describe-load-balancers --query 'LoadBalancers[*].[LoadBalancerName,CreatedTime,DNSName]' --output table

    Check Traffic Metrics:

    •   Use Amazon CloudWatch to monitor traffic and requests to each ELB. ELBs with zero or minimal traffic over a significant period might be unused.
    •   Check metrics like RequestCount, HealthyHostCount, and UnHealthyHostCount.

    To differentiate between real traffic and traffic generated by health checks on an Elastic Load Balancer (ELB), you can follow these steps:

    Understand the Metrics

    •   RequestCount: This metric shows the total number of requests handled by the ELB. By default, it includes both real traffic and health check requests.
    •   HealthyHostCount and UnHealthyHostCount: These metrics show the number of healthy or unhealthy instances behind the ELB, but they don’t directly reflect user traffic.

    To find out the real traffic for each type of Load Balancer in AWS (Classic, Network, and Application)

    To find out the real traffic for each type of Load Balancer in AWS (Classic, Network, and Application), you can refer to specific metrics in CloudWatch. Here’s a breakdown of the key metrics to monitor real traffic for each type of Load Balancer:

    1. Classic Load Balancer (CLB) • RequestCount: The total number of requests handled by the load balancer. This metric includes all incoming requests, which is useful for understanding the volume of traffic.
      • HealthyHostCount: The number of healthy instances registered with the load balancer.
      • UnHealthyHostCount: The number of unhealthy instances registered with the load balancer.
      • Latency: The time taken for the load balancer to respond to a request. This can help gauge the load and performance of the load balancer.
      • HTTPCode_Backend_2XX: The number of 2xx response codes from the backend, indicating successful requests.
      • HTTPCode_Backend_4XX: The number of 4xx response codes from the backend, indicating client errors.
      • HTTPCode_Backend_5XX: The number of 5xx response codes from the backend, indicating server errors.
      • BackendConnectionErrors: The number of connections that were not successfully established between the load balancer and the backend instances.
    2. Network Load Balancer (NLB) • ActiveFlowCount: The total number of active TCP/UDP flows (or connections) processed by the load balancer. This metric gives you an idea of the number of ongoing connections.
      • NewFlowCount: The number of new connections established by the load balancer per second.
      • ProcessedBytes: The total number of bytes processed by the load balancer, including both incoming and outgoing traffic. This metric can be used to estimate the volume of traffic.
      • HealthyHostCount: The number of healthy targets (backend instances) for each load balancer target group.
      • UnHealthyHostCount: The number of unhealthy targets (backend instances) for each load balancer target group.
      • TCP_Client_Reset_Count: The number of reset (RST) packets sent from a client to a target. High numbers may indicate issues with traffic handling.
      • TCP_Target_Reset_Count: The number of reset (RST) packets sent from a target to a client. It can indicate potential problems with target health.
    3. Application Load Balancer (ALB) • RequestCount: The number of requests processed by the load balancer. This metric provides an overall view of the traffic hitting the ALB.
      • TargetResponseTime: The average time taken for a target to respond to a request. This helps in understanding the performance of the targets.
      • HTTPCode_Target_2XX_Count: The number of 2xx response codes from targets, indicating successful requests.
      • HTTPCode_Target_3XX_Count: The number of 3xx response codes from targets, indicating redirects.
      • HTTPCode_Target_4XX_Count: The number of 4xx response codes from targets, indicating client errors.
      • HTTPCode_Target_5XX_Count: The number of 5xx response codes from targets, indicating server errors.
      • TargetConnectionErrorCount: The number of connections that were not successfully established between the load balancer and the target.
      • ConsumedLCUs: Load Balancer Capacity Units (LCUs) consumed by the ALB, which helps in understanding the resource utilization and cost associated with the ALB.

    Key Considerations for Real Traffic Analysis:

    •   Filtering Health Check Traffic: When analyzing RequestCount and similar metrics, remember that they might include health check traffic. To focus only on real user traffic, consider filtering out requests to known health check endpoints or use application-level logs to differentiate between real and health check traffic.
    •   HealthyHostCount and UnHealthyHostCount: These metrics are crucial to understanding the state of the backend targets and ensuring that your load balancer is distributing traffic effectively.
    #!/bin/bash
    # Set the time period (last 1 month)
    END_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
    START_TIME=$(date -u -v-30d +"%Y-%m-%dT%H:%M:%SZ")
    # Function to fetch metrics for Classic Load Balancer (CLB)
    fetch_clb_metrics() {
    echo "Fetching RequestCount for Classic Load Balancers..."
    CLB_NAMES=$(aws elb describe-load-balancers --query "LoadBalancerDescriptions[].LoadBalancerName" --output text --no-verify-ssl 2>/dev/null)
    for CLB_NAME in $CLB_NAMES; do
    aws cloudwatch get-metric-statistics \
    --metric-name RequestCount \
    --start-time "$START_TIME" \
    --end-time "$END_TIME" \
    --period 86400 \
    --namespace AWS/ELB \
    --statistics Sum \
    --dimensions Name=LoadBalancerName,Value="$CLB_NAME" \
    --query "Datapoints[*].[Timestamp,Sum]" \
    --output text \
    --no-verify-ssl 2>/dev/null | sort
    done
    }
    # Function to fetch metrics for Application Load Balancer (ALB)
    fetch_alb_metrics() {
    echo "Fetching RequestCount for Application Load Balancers..."
    ALB_ARNS=$(aws elbv2 describe-load-balancers --query "LoadBalancers[?Type=='application'].LoadBalancerArn" --output text --no-verify-ssl 2>/dev/null)
    for ALB_ARN in $ALB_ARNS; do
    aws cloudwatch get-metric-statistics \
    --metric-name RequestCount \
    --start-time "$START_TIME" \
    --end-time "$END_TIME" \
    --period 86400 \
    --namespace AWS/ApplicationELB \
    --statistics Sum \
    --dimensions Name=LoadBalancer,Value="$ALB_ARN" \
    --query "Datapoints[*].[Timestamp,Sum]" \
    --output text \
    --no-verify-ssl 2>/dev/null | sort
    done
    }
    # Function to fetch metrics for Network Load Balancer (NLB)
    fetch_nlb_metrics() {
    echo "Fetching ActiveFlowCount for Network Load Balancers..."
    NLB_ARNS=$(aws elbv2 describe-load-balancers --query "LoadBalancers[?Type=='network'].LoadBalancerArn" --output text --no-verify-ssl 2>/dev/null)
    for NLB_ARN in $NLB_ARNS; do
    aws cloudwatch get-metric-statistics \
    --metric-name ActiveFlowCount \
    --start-time "$START_TIME" \
    --end-time "$END_TIME" \
    --period 86400 \
    --namespace AWS/NetworkELB \
    --statistics Sum \
    --dimensions Name=LoadBalancer,Value="$NLB_ARN" \
    --query "Datapoints[*].[Timestamp,Sum]" \
    --output text \
    --no-verify-ssl 2>/dev/null | sort
    done
    }
    # Fetch metrics
    fetch_clb_metrics
    fetch_alb_metrics
    fetch_nlb_metrics
    view raw Linux.sh hosted with ❤ by GitHub
    #!/bin/bash
    # Suppress InsecureRequestWarning warnings
    export PYTHONWARNINGS="ignore:Unverified HTTPS request"
    # Set the time period (last 1 month)
    END_TIME=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
    START_TIME=$(date -u -v-30d +"%Y-%m-%dT%H:%M:%SZ")
    # Function to fetch metrics for Classic Load Balancer (CLB)
    fetch_clb_metrics() {
    echo "Fetching RequestCount for Classic Load Balancers..."
    CLB_NAMES=$(aws elb describe-load-balancers --query "LoadBalancerDescriptions[].LoadBalancerName" --output text --no-verify-ssl 2>/dev/null)
    for CLB_NAME in $CLB_NAMES; do
    echo "Load Balancer: $CLB_NAME"
    aws cloudwatch get-metric-statistics \
    --metric-name RequestCount \
    --start-time "$START_TIME" \
    --end-time "$END_TIME" \
    --period 86400 \
    --namespace AWS/ELB \
    --statistics Sum \
    --dimensions Name=LoadBalancerName,Value="$CLB_NAME" \
    --query "Datapoints[*].[Timestamp,Sum]" \
    --output text \
    --no-verify-ssl 2>/dev/null | sort | awk -v lb="$CLB_NAME" '{print lb "\t" $0}'
    done
    }
    # Function to fetch metrics for Application Load Balancer (ALB)
    fetch_alb_metrics() {
    echo "Fetching RequestCount for Application Load Balancers..."
    ALB_ARNS=$(aws elbv2 describe-load-balancers --query "LoadBalancers[?Type=='application'].LoadBalancerArn" --output text --no-verify-ssl 2>/dev/null)
    for ALB_ARN in $ALB_ARNS; do
    ALB_NAME=$(aws elbv2 describe-load-balancers --load-balancer-arns "$ALB_ARN" --query "LoadBalancers[0].LoadBalancerName" --output text --no-verify-ssl 2>/dev/null)
    echo "Load Balancer: $ALB_NAME"
    aws cloudwatch get-metric-statistics \
    --metric-name RequestCount \
    --start-time "$START_TIME" \
    --end-time "$END_TIME" \
    --period 86400 \
    --namespace AWS/ApplicationELB \
    --statistics Sum \
    --dimensions Name=LoadBalancer,Value="$ALB_ARN" \
    --query "Datapoints[*].[Timestamp,Sum]" \
    --output text \
    --no-verify-ssl 2>/dev/null | sort | awk -v lb="$ALB_NAME" '{print lb "\t" $0}'
    done
    }
    # Function to fetch metrics for Network Load Balancer (NLB)
    fetch_nlb_metrics() {
    echo "Fetching ActiveFlowCount for Network Load Balancers..."
    NLB_ARNS=$(aws elbv2 describe-load-balancers --query "LoadBalancers[?Type=='network'].LoadBalancerArn" --output text --no-verify-ssl 2>/dev/null)
    for NLB_ARN in $NLB_ARNS; do
    NLB_NAME=$(aws elbv2 describe-load-balancers --load-balancer-arns "$NLB_ARN" --query "LoadBalancers[0].LoadBalancerName" --output text --no-verify-ssl 2>/dev/null)
    echo "Load Balancer: $NLB_NAME"
    aws cloudwatch get-metric-statistics \
    --metric-name ActiveFlowCount \
    --start-time "$START_TIME" \
    --end-time "$END_TIME" \
    --period 86400 \
    --namespace AWS/NetworkELB \
    --statistics Sum \
    --dimensions Name=LoadBalancer,Value="$NLB_ARN" \
    --query "Datapoints[*].[Timestamp,Sum]" \
    --output text \
    --no-verify-ssl 2>/dev/null | sort | awk -v lb="$NLB_NAME" '{print lb "\t" $0}'
    done
    }
    # Fetch metrics
    fetch_clb_metrics
    fetch_alb_metrics
    fetch_nlb_metrics
    view raw MACOS.sh hosted with ❤ by GitHub
    Subscribe
    Notify of
    guest


    0 Comments
    Newest
    Oldest Most Voted
    Inline Feedbacks
    View all comments

    Certification Courses

    DevOpsSchool has introduced a series of professional certification courses designed to enhance your skills and expertise in cutting-edge technologies and methodologies. Whether you are aiming to excel in development, security, or operations, these certifications provide a comprehensive learning experience. Explore the following programs:

    DevOps Certification, SRE Certification, and DevSecOps Certification by DevOpsSchool

    Explore our DevOps Certification, SRE Certification, and DevSecOps Certification programs at DevOpsSchool. Gain the expertise needed to excel in your career with hands-on training and globally recognized certifications.

    0
    Would love your thoughts, please comment.x
    ()
    x