> ## Documentation Index
> Fetch the complete documentation index at: https://cloudanix.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# No Unused ELBs Should Be Present

### More Info:

You should not have unused Elastic Load Balancers in your AWS account. Unused ELBs should be deleted to help lower the cost of your monthly AWS bill.

### Risk Level

Low

### Address

Cost Optimisation

### Compliance Standards

HITRUST, SOC2, NISTCSF

### Triage and Remediation

<Tabs>
  <Tab title="Remediation">
    ### Remediation

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        To remediate the misconfiguration of having no unused ELBs present in AWS, you can follow the below steps:

        1. Sign in to the AWS Management Console.

        2. Go to the EC2 dashboard.

        3. Click on "Load Balancers" from the left-hand menu.

        4. Identify any unused ELBs that are present in the list.

        5. Select the unused ELB and click on "Actions" and then "Delete".

        6. Confirm the deletion by clicking on "Yes, Delete".

        7. Repeat the above steps for all unused ELBs that are present.

        By following these steps, you will be able to remediate the misconfiguration of having no unused ELBs present in AWS.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the misconfiguration of having unused ELBs in AWS, you can follow the below steps using AWS CLI:

        1. List all the ELBs in the AWS account using the following command:

        ```
        aws elb describe-load-balancers
        ```

        2. Identify the ELBs that are not being used and note down their names.

        3. Delete the unused ELBs using the following command:

        ```
        aws elb delete-load-balancer --load-balancer-name <ELB-Name>
        ```

        4. Repeat step 3 for all the unused ELBs that you identified in step 2.

        5. Verify that all the unused ELBs have been deleted using the following command:

        ```
        aws elb describe-load-balancers
        ```

        This should remediate the misconfiguration of having unused ELBs in AWS.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the misconfiguration "No Unused ELBs Should Be Present" in AWS using Python, you can follow the below steps:

        1. Import the required AWS SDK modules using the boto3 library in Python.
        2. Use the describe\_load\_balancers() method to list all the load balancers available in your AWS account.
        3. Use the describe\_instance\_health() method to check the instances associated with each load balancer and their health status.
        4. Identify the unused load balancers by checking if there are any instances associated with them.
        5. Use the delete\_load\_balancer() method to delete the unused load balancers.

        Here's the sample Python code to remediate the misconfiguration "No Unused ELBs Should Be Present" in AWS:

        ```
        import boto3

        # Create an EC2 client
        elb_client = boto3.client('elbv2')

        # Get all the load balancers in the account
        response = elb_client.describe_load_balancers()

        # Loop through each load balancer and check if there are any instances associated with it
        for lb in response['LoadBalancers']:
            lb_arn = lb['LoadBalancerArn']
            instances = elb_client.describe_target_health(TargetGroupArn=lb_arn)

            # If there are no instances associated with the load balancer, delete it
            if len(instances['TargetHealthDescriptions']) == 0:
                elb_client.delete_load_balancer(LoadBalancerArn=lb_arn)
        ```

        Note: Before running the script, make sure that you have configured the AWS credentials in your environment.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>

### Additional Reading:

* [https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html](https://docs.aws.amazon.com/elasticloadbalancing/latest/classic/elb-cloudwatch-metrics.html)
