Bird
Raised Fist0
AWScloud~5 mins

Cross-zone load balancing in AWS - Commands & Configuration

Choose your learning style10 modes available
Introduction
When you have servers in different locations to handle your app traffic, you want to share the work evenly. Cross-zone load balancing helps send users to servers in all locations fairly, so no server gets too busy or too quiet.
When your app runs in multiple data centers or zones and you want to spread user requests evenly across all servers.
When some zones have more servers than others and you want to make sure all servers get a fair share of traffic.
When you want to improve your app's availability by using servers from all zones even if one zone is busier.
When you notice some servers are overloaded while others are idle in different zones.
When you want to avoid users being sent only to servers in their own zone, which can cause uneven load.
Config File - elb-cross-zone-config.json
elb-cross-zone-config.json
{
  "LoadBalancerName": "my-app-elb",
  "Listeners": [
    {
      "Protocol": "HTTP",
      "LoadBalancerPort": 80,
      "InstanceProtocol": "HTTP",
      "InstancePort": 80
    }
  ],
  "AvailabilityZones": ["us-east-1a", "us-east-1b"],
  "CrossZoneLoadBalancing": {
    "Enabled": true
  }
}

This JSON configures an Elastic Load Balancer (ELB) named my-app-elb that listens on HTTP port 80. It is set to work across two availability zones: us-east-1a and us-east-1b. The key part is CrossZoneLoadBalancing.Enabled: true, which tells AWS to share incoming traffic evenly across all servers in both zones, not just within each zone.

Commands
This command creates a new Elastic Load Balancer named 'my-app-elb' that listens on HTTP port 80 and spans two availability zones to distribute traffic.
Terminal
aws elb create-load-balancer --load-balancer-name my-app-elb --listeners Protocol=HTTP,LoadBalancerPort=80,InstanceProtocol=HTTP,InstancePort=80 --availability-zones us-east-1a us-east-1b
Expected OutputExpected
{ "DNSName": "my-app-elb-1234567890.us-east-1.elb.amazonaws.com" }
→
--load-balancer-name - Sets the name of the load balancer.
→
--listeners - Defines the protocol and ports for incoming and backend traffic.
→
--availability-zones - Specifies which zones the load balancer will cover.
This command enables cross-zone load balancing on the existing load balancer to ensure traffic is spread evenly across all zones.
Terminal
aws elb modify-load-balancer-attributes --load-balancer-name my-app-elb --load-balancer-attributes '{"CrossZoneLoadBalancing":{"Enabled":true}}'
Expected OutputExpected
{ "LoadBalancerName": "my-app-elb", "LoadBalancerAttributes": { "CrossZoneLoadBalancing": { "Enabled": true } } }
→
--load-balancer-name - Specifies which load balancer to modify.
→
--load-balancer-attributes - Sets the attributes, here enabling cross-zone load balancing.
This command checks the current settings of the load balancer to confirm cross-zone load balancing is enabled.
Terminal
aws elb describe-load-balancer-attributes --load-balancer-name my-app-elb
Expected OutputExpected
{ "LoadBalancerAttributes": { "CrossZoneLoadBalancing": { "Enabled": true }, "AccessLog": { "Enabled": false }, "ConnectionDraining": { "Enabled": false } } }
→
--load-balancer-name - Specifies which load balancer to inspect.
Key Concept

If you remember nothing else from this pattern, remember: enabling cross-zone load balancing makes sure all your servers in different zones share the work fairly.

Common Mistakes
Not enabling cross-zone load balancing after creating the load balancer.
Traffic will only be balanced within each zone, causing uneven load if zones have different numbers of servers.
Run the modify-load-balancer-attributes command to enable cross-zone load balancing.
Specifying only one availability zone when creating the load balancer.
The load balancer cannot distribute traffic across multiple zones if only one zone is included.
Include all desired availability zones in the create-load-balancer command.
Assuming cross-zone load balancing is enabled by default.
By default, it is disabled for some load balancer types, so traffic may not be evenly distributed.
Always verify and explicitly enable cross-zone load balancing if needed.
Summary
Create an Elastic Load Balancer spanning multiple availability zones to distribute traffic.
Enable cross-zone load balancing to share traffic evenly across all servers in all zones.
Verify the load balancer attributes to confirm cross-zone load balancing is active.

Practice

(1/5)
1. What is the main benefit of enabling cross-zone load balancing in AWS Elastic Load Balancer?
easy
A. It increases the maximum number of connections per target.
B. It automatically scales the number of Availability Zones.
C. It evenly distributes incoming traffic across all registered targets in all enabled Availability Zones.
D. It encrypts all traffic between the load balancer and targets.

Solution

  1. Step 1: Understand cross-zone load balancing purpose

    Cross-zone load balancing spreads traffic evenly across targets in all zones, preventing uneven load.
  2. Step 2: Compare options to this purpose

    Only It evenly distributes incoming traffic across all registered targets in all enabled Availability Zones. describes this even distribution. Other options describe unrelated features.
  3. Final Answer:

    It evenly distributes incoming traffic across all registered targets in all enabled Availability Zones. -> Option C
  4. Quick Check:

    Cross-zone load balancing = even traffic spread [OK]
Hint: Cross-zone means traffic spreads evenly across zones [OK]
Common Mistakes:
  • Confusing cross-zone with encryption or scaling
  • Thinking it increases max connections per target
  • Assuming it changes number of zones automatically
2. Which of the following is the correct way to enable cross-zone load balancing in an AWS Application Load Balancer using Terraform?
easy
A. enable_cross_zone_load_balancing = false
B. cross_zone_load_balancing = true
C. cross_zone_enabled = true
D. enable_cross_zone_load_balancing = true

Solution

  1. Step 1: Recall Terraform attribute for cross-zone load balancing

    The correct attribute is enable_cross_zone_load_balancing and it must be set to true to enable.
  2. Step 2: Match options to correct syntax

    Only enable_cross_zone_load_balancing = true uses the exact attribute name and sets it to true.
  3. Final Answer:

    enable_cross_zone_load_balancing = true -> Option D
  4. Quick Check:

    Terraform attribute = enable_cross_zone_load_balancing true [OK]
Hint: Look for exact attribute name with true value [OK]
Common Mistakes:
  • Using incorrect attribute names like cross_zone_load_balancing
  • Setting the value to false instead of true
  • Confusing with other unrelated settings
3. Given the following AWS CLI command to enable cross-zone load balancing on a Classic Load Balancer:
aws elb modify-load-balancer-attributes --load-balancer-name my-load-balancer --load-balancer-attributes '{"CrossZoneLoadBalancing":{"Enabled":true}}'

What will be the effect of running this command?
medium
A. Cross-zone load balancing will be disabled for the load balancer.
B. Cross-zone load balancing will be enabled, distributing traffic evenly across zones.
C. The load balancer will be deleted.
D. The command will fail due to syntax error.

Solution

  1. Step 1: Analyze the AWS CLI command structure

    The command modifies load balancer attributes, specifically enabling CrossZoneLoadBalancing by setting Enabled to true.
  2. Step 2: Understand the effect of enabling CrossZoneLoadBalancing

    Enabling it causes traffic to be evenly distributed across all registered targets in all zones.
  3. Final Answer:

    Cross-zone load balancing will be enabled, distributing traffic evenly across zones. -> Option B
  4. Quick Check:

    Enable CrossZoneLoadBalancing true = even traffic spread [OK]
Hint: Enabled true means cross-zone load balancing is active [OK]
Common Mistakes:
  • Thinking the command disables the feature
  • Assuming the load balancer is deleted
  • Believing the command syntax is incorrect
4. You configured cross-zone load balancing on your Network Load Balancer but notice traffic is still uneven across zones. What is the most likely cause?
medium
A. You forgot to register targets in all Availability Zones.
B. Cross-zone load balancing is not supported on Network Load Balancers.
C. Cross-zone load balancing requires manual DNS updates.
D. You must enable cross-zone load balancing on each target instance.

Solution

  1. Step 1: Recall cross-zone load balancing support on Network Load Balancers

    Network Load Balancers support cross-zone load balancing, but it must be enabled and targets must be registered in all zones.
  2. Step 2: Identify why traffic is uneven

    If targets are missing in some zones, traffic cannot be balanced evenly despite cross-zone load balancing being enabled.
  3. Final Answer:

    You forgot to register targets in all Availability Zones. -> Option A
  4. Quick Check:

    Targets missing in zones = uneven traffic [OK]
Hint: Ensure targets exist in all zones for balancing [OK]
Common Mistakes:
  • Thinking cross-zone load balancing is unsupported on NLB
  • Believing DNS updates are needed
  • Assuming enabling on targets is required
5. You have an Application Load Balancer spanning three Availability Zones with cross-zone load balancing enabled. One zone has only one healthy target, while the others have three each. How does cross-zone load balancing affect traffic distribution?
hard
A. Traffic is evenly distributed across all targets regardless of zone count.
B. Traffic is evenly distributed across zones, so the zone with one target gets one-third of traffic.
C. Traffic is sent only to zones with the most targets.
D. Traffic is distributed randomly without considering zones or targets.

Solution

  1. Step 1: Understand cross-zone load balancing behavior

    With cross-zone load balancing enabled, each load balancer node distributes traffic evenly across all healthy registered targets, regardless of their Availability Zone.
  2. Step 2: Apply to given scenario

    Total healthy targets: 1 + 3 + 3 = 7. Each target receives approximately equal traffic (1/7), so the zone with one target gets about 1/7 of total traffic.
  3. Final Answer:

    Traffic is evenly distributed across all targets regardless of zone count. -> Option A
  4. Quick Check:

    Cross-zone load balancing = even across all targets [OK]
Hint: Cross-zone balances evenly across all targets, ignoring zone boundaries [OK]
Common Mistakes:
  • Confusing with default zone-isolated balancing (even per zone)
  • Thinking traffic prefers zones with more targets
  • Believing distribution ignores target count
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard