> ## 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.

# ELBs Should Have Cross Zone Enabled

### More Info:

For higher availability and reliability, ELBs should work with cross zone nodes.

### Risk Level

Low

### Address

Reliability, Security

### Compliance Standards

NIST, SOC2, GDPR, HITRUST, NISTCSF

### Triage and Remediation

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

    <AccordionGroup>
      <Accordion title="Using Console" defaultOpen="true">
        Sure, here are the step-by-step instructions to remediate the ELBs should have cross-zone enabled misconfiguration for AWS using the AWS Console:

        1. Open the AWS Management Console and navigate to the EC2 Dashboard.

        2. From the left-hand menu, select "Load Balancers".

        3. Select the ELB that you want to remediate.

        4. Click on the "Attributes" tab.

        5. Scroll down to the "Cross-Zone Load Balancing" section and click on the "Edit" button.

        6. Select "Yes" for the "Enable Cross-Zone Load Balancing" option.

        7. Click on the "Save" button to save the changes.

        That's it! You have now successfully remediated the ELBs should have cross-zone enabled misconfiguration for AWS using the AWS Console.

        #
      </Accordion>

      <Accordion title="Using CLI">
        To remediate the misconfiguration "ELBs should have cross-zone enabled" in AWS using AWS CLI, follow these steps:

        1. Open the AWS CLI on your local machine.

        2. Run the following command to enable cross-zone load balancing for all existing ELBs in the current region:

        ```
        aws elb modify-load-balancer-attributes --load-balancer-name <ELB_NAME> --load-balancer-attributes "{\"CrossZoneLoadBalancing\":{\"Enabled\":true}}"
        ```

        Replace `<ELB_NAME>` with the name of the ELB that needs to be remediated.

        3. Run the following command to enable cross-zone load balancing for all new ELBs created in the current region:

        ```
        aws elb create-lb-cookie-stickiness-policy --load-balancer-name <ELB_NAME> --policy-name "cross-zone-policy" --cookie-expiration-period 60
        ```

        Replace `<ELB_NAME>` with the name of the ELB that needs to be remediated.

        4. Verify that cross-zone load balancing is enabled for the ELB by running the following command:

        ```
        aws elb describe-load-balancer-attributes --load-balancer-name <ELB_NAME> --query 'LoadBalancerAttributes.CrossZoneLoadBalancing.Enabled'
        ```

        Replace `<ELB_NAME>` with the name of the ELB that was remediated.

        5. Repeat these steps for all ELBs in the current region that require remediation.
      </Accordion>

      <Accordion title="Using Python">
        To remediate the misconfiguration of ELBs not having cross-zone enabled in AWS using Python, you can follow the below steps:

        1. Import the necessary libraries:

        ```python theme={null}
        import boto3
        ```

        2. Create an AWS client for Elastic Load Balancing:

        ```python theme={null}
        elb_client = boto3.client('elbv2')
        ```

        3. Get the list of all the ELBs:

        ```python theme={null}
        elbs = elb_client.describe_load_balancers()
        ```

        4. Loop through each ELB and check if cross-zone load balancing is enabled. If not, enable it:

        ```python theme={null}
        for elb in elbs['LoadBalancers']:
            elb_arn = elb['LoadBalancerArn']
            elb_attributes = elb_client.describe_load_balancer_attributes(LoadBalancerArn=elb_arn)
            if not elb_attributes['Attributes'][0]['Value']:
                elb_client.modify_load_balancer_attributes(
                    LoadBalancerArn=elb_arn,
                    Attributes=[
                        {
                            'Key': 'load_balancing.cross_zone.enabled',
                            'Value': 'true'
                        }
                    ]
                )
        ```

        5. Verify that cross-zone load balancing is enabled for all the ELBs:

        ```python theme={null}
        for elb in elbs['LoadBalancers']:
            elb_arn = elb['LoadBalancerArn']
            elb_attributes = elb_client.describe_load_balancer_attributes(LoadBalancerArn=elb_arn)
            if not elb_attributes['Attributes'][0]['Value']:
                print(f"{elb['LoadBalancerName']} - Cross-Zone Load Balancing is not Enabled")
            else:
                print(f"{elb['LoadBalancerName']} - Cross-Zone Load Balancing is Enabled")
        ```

        By following these steps, you can remediate the misconfiguration of ELBs not having cross-zone enabled in AWS using Python.
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>

### Additional Reading:

* [https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-subnets.html](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-subnets.html)
