How to Set Up an HTTP LoadBalancer
In this example, you create a LoadBalancer for an HTTP service. You specify that the LoadBalancer listens on port 80 and distributes traffic to port 8080 on the instances. You also specify that Availability Zone us-east-1a is enabled for your LoadBalancer. Once the LoadBalancer is created, you configure an application health check for the instances, and register the instances with the LoadBalancer.
Preconditions:
-
Your AWS account is signed up for Amazon EC2
-
In Availability Zone us-east-1a, you have launched the instances you intend to register with your LoadBalancer
-
The instances to be registered with your LoadBalancer respond to the target of the health check with an HTTP status code 200
API Example
To set up an HTTP LoadBalancer
-
Call CreateLoadBalancer with the following parameters:
-
AvailabilityZones =
us-east-1a
-
Listeners
-
Protocol
=HTTP
-
InstancePort
=8080
-
LoadBalancerPort
=80
-
-
LoadBalancerName
=MyLoadBalancer
The operation returns the DNS name of your LoadBalancer. You can then map that to any other domain name (such as www.mywebsite.com) using a CNAME or some other technique.
-
-
Call ConfigureHealthCheck with the following parameters:
-
LoadBalancerName
=MyLoadBalancer
-
Target
=http:8080/ping
Note Make sure your instances respond to /ping on port 8080 with an HTTP 200 status code. -
Interval
=30
-
Timeout
=3
-
HealthyThreshold
=2
-
UnhealthyThreshold
=2
-
-
Call RegisterInstancesWithLoadBalancer with the following parameters:
-
LoadBalancerName
=MyLoadBalancer
-
Instances = [
i-4f8cf126
,i-0bb7ca62
]
-
Command Line Tools Example
To set up an HTTP LoadBalancer
-
Use the elb-create-lb command as in the following example.
PROMPT> elb-create-lb MyLoadBalancer --headers --listener "lb-port=80,instance-port=8080,protocol=HTTP" --availability-zones us-east-1a
Elastic Load Balancing returns the following:
DNS-NAME DNS-NAME DNS-NAME MyLoadBalancer-2111276808.us-east-1.elb.amazonaws.com
-
Use the elb-configure-healthcheck command as in the following example.
PROMPT> elb-configure-healthcheck MyLoadBalancer --headers --target "HTTP:8080/ping" --interval 30 --timeout 3 --unhealthy-threshold 2 --healthy-threshold 2
Elastic Load Balancing returns the following:
HEALTH-CHECK TARGET INTERVAL TIMEOUT HEALTHY-THRESHOLD UNHEALTHY-THRESHOLD HEALTH-CHECK HTTP:8080/ping 30 3 2 2
-
Use the elb-register-instances-with-lb command as in the following example.
PROMPT> elb-register-instances-with-lb MyLoadBalancer --headers --instances i-4f8cf126,i-0bb7ca62
Elastic Load Balancing returns the following:
INSTANCE INSTANCE-ID INSTANCE i-4f8cf126 INSTANCE i-0bb7ca62
Give Us Your Feedback
Your input is important to us to help make our documentation helpful and easy to use. Please take a minute to give us your feedback on how well we were able to help you use Elastic Load Balancing. Just click this feedback link. Thank you.