Elastic Load Balancing interface for AWS ======================================== What is Elastic Load Balancing? ------------------------------- Amazon Web Services (AWS) provides Elastic Load Balancing to automatically distribute incoming web traffic across multiple Amazon Elastic Compute Cloud (Amazon EC2) instances. With Elastic Load Balancing, you can add and remove EC2 instances as your needs change without disrupting the overall flow of information. If one EC2 instance fails, Elastic Load Balancing automatically reroutes the traffic to the remaining running EC2 instances. If the failed EC2 instance is restored, Elastic Load Balancing restores the traffic to that instance. Elastic Load Balancing offers clients a single point of contact, and it can also serve as the first line of defense against attacks on your network. You can offload the work of encryption and decryption to Elastic Load Balancing, so your servers can focus on their main task. Ok Now Tell me some advantages of using Elastic Load Balancing -------------------------------------------------------------- * Distribution of requests to Amazon EC2 instances (servers)in multiple vailability Zones so that the risk of overloading one single instance is minimized. * Continuous monitoring of the health of Amazon EC2 instances registered with the load balancer. * Support for end-to-end traffic encryption on those networks that use secure (HTTPS/SSL) connections. * Support for the sticky session feature, which is the ability to "stick" user sessions to specific Amazon EC2 instances. * Association of the load balancer with your domain name. * Supports use of both the Internet Protocol version 4 (IPv4) and Internet Protocol version 6 (IPv6). "How it works?" would be nice to share -------------------------------------- Elastic Load Balancing consists of two components: the load balancers and the controller service. The load balancers monitor the traffic and handle requests that come in through the Internet. The controller service monitors the load balancers, adding and removing load balancers as needed and verifying that the load balancers are functioning properly. * The client sends a URL request to DNS servers to access your application. For example, myLB-1234567890.us-east-1.elb.amazonaws.com. * Then The client looks for the resolution of the DNS name sent by the DNS server. * The client then opens a connection to the machine at the provided IP address. The instance at this address is the load balancer you created. * The load balancer checks the health states of all the registered EC2 application instances within the selected Availability Zones * Then load balancer routes the client request to the healthy EC2 application instance identified in the previous step. That's not enough, you want to learn more about ELB, then Refer `AWS site `_. Now lets dive into the tutorial which will focus on libcloud Elastic Load Balancing interface for AWS. 1. Creating a Connection ------------------------ The first step in accessing ELB is to create a connection to the service. So, when you instantiate an ELB driver you need to pass the following arguments to the driver constructor: * ``key`` - Your AWS API key * ``secret`` - Your AWS secret key * ``region`` - The region of your AWS instance host point (e.g ``us-west-2`` for ``US West (Oregon) Region``) Typically this will lead to: .. literalinclude:: /examples/loadbalancer/elb/create_lb_connection_for_aws.py :language: python if everything gone well; means if your console has not yelled any error then your connection has been established. by the way if you have difficulty in getting your 'access key' and 'secret key' id's, look at security credentials page of AWS management console. The base `libcloud` ELB API allows you to: * list, create, attach, detach, delete load balancer * list protocols related to load balancer Non-standard functionality and extension methods ------------------------------------------------ The AWS ELB driver exposes a lot of `libcloud` non-standard functionalities through extension methods and arguments. These functionalities include: * list laod balancer policy * list load balancer policy types * create, delete load balancer policy * create listeners for load balancer * enable/disable policies on backend server & listeners 2. Getting Existing Load Balancers ---------------------------------- To retrieve any exiting load balancers available .. literalinclude:: /examples/loadbalancer/elb/list_load_balancer.py :language: python this will return you a list of load balancers ``[]`` 3. Creating New Load Balancers ------------------------------ To create new load balancer initialise some members for the load balancer first .. literalinclude:: /examples/loadbalancer/elb/create_load_balancer.py :language: python Ok if everything is fine; you will see this on your python shell screen ``[