AWS Elastic Load Balancer Cookbook

31 / Dec / 2013 by Tejprakash Sharma 1 comments

Elastic Load Balancer is a service provided by AWS that is used to distribute incoming application traffic across multiple EC2 instances and availability zones automatically.  Elastic Load Balancer continuously monitors and detects unhealthy instances, after which it automatically re-routes all the traffic to healthy instances until the unhealthy instances have been restored.  By following this mechanism, It ensures that traffic routes only to the healthy instances.

Few of the major advantages of Elastic Load Balancers (ELBs) are:

  • It automatically scales its request handling capacity to meet the demands of application traffic.
  • It also gives you the integration with Auto Scaling to ensure back-end capacity to meet varying levels of traffic levels without requiring manual intervention.
  • With integrated certificate management and SSL decryption provided by Elastic Load Balancer, you can centrally manage the SSL settings of the load balancer and offload CPU intensive work from your instances.

Based on different use cases, I have mentioned a few of the commands that you can use to configure ELBs. These commands can be really handy when you are either trying to check, configure or delete ELBs.

Create a new ELB
It creates a new ELB and return the DNS name that includes region in which the respective ELB has been created.

[shell]aws  elb  create-load-balancer  –load-balancer-name ELB_NAME –listeners Protocol=PROTOCOL,LoadBalancerPort=PORT_NO,InstanceProtocol=PROTOCOL,InstancePort= PORT_NO Protocol=PROTOCOL,LoadBalancerPort= PORT_NO,InstanceProtocol= PROTOCOL,InstancePort= PORT_NO,SSLCertificateId=SSL_ID –region REGION –subnets SUBNET_ID –security-groups SECURITY_GROUP_ID[/shell]

Add health checks to the ELB
It specifies the ELB health check settings used to verify the instance health state.

[shell]aws elb configure-health-check –load-balancer-name ELB NAME –health-check Target=PING_URL,Interval=INTERVAL_TIME,Timeout=TIMEOUT_PERIOD,UnhealthyThreshold= INTEGER,HealthyThreshold=INTERGER [/shell]

Show All ELB
It returns the detailed information about all the ELBs created in your account.

[shell]aws elb describe-load-balancers[/shell]

Show a particular ELB
It returns detailed information about a particular mentioned ELB.

[shell]aws elb describe-load-balancers –load-balancer-names ELB_NAME[/shell]

Apply a security group to an ELB
It applies a security group to given ELB. You can assign multiple security groups ids, separated by blank space.

[shell]aws elb apply-security-groups-to-load-balancer –load-balancer-name  ELB_NAME –security-groups SECURITY_GROUP_ID[/shell]

 Register an Instance to an ELB
It registers the instances by ELB. More than one instance id can be attached to the ELB but instance should be in the registered availability zone or subnet to the ELB.

[shell]aws elb register-instances-with-load-balancer –load-balancer-name ELB_NAME –instances  INSTANCE_ID[/shell]

Attach a subnet to an ELB
It adds a new subnet to load balancer. More than one subnet can be added at a time but it can be only passed by separating each ID with blank space.

[shell]aws elb attach-load-balancer-to-subnets  –load-balancer-name ELB_NAME –subnets SUBNET_ID[/shell]

Delete an ELB
By using below mentioned command, one can easily delete the given load balancer.

[shell]aws elb delete-load-balancer –load-balancer-name ELB_NAME[/shell]

 Set SSL certificate to an ELB
It will add the SSL certificate to the load balancer. You can also specify the port nummber on which that particular SSL certificate will be added but that port should be open for ELB.

[shell]aws elb set-load-balancer-listener-ssl-certificate –load-balancer-name ELB_NAME –load-balancer-port PORT_NO –ssl-certificate-id SSL_ID[/shell]

Delete port from ELB
It will delete the listener from ELB for given port number.

[shell]aws elb delete-load-balancer-listeners –load-balancer-name ELB_NAME –load-balancer-ports PORT_NO[/shell]

Detach ELB from a subnet
It will detach the subnet from load balancer and after removal of subnet, all the instances in this subnet also gets automatically removed from load balancer.

[shell]aws elb detach-load-balancer-from-subnets –load-balancer-name  ELB_NAME –subnets SUBNET_ID[/shell]

Deregister instances from ELB
It will de-register the Instance from load balancer. Once the Instance is de-registered, no more traffic will be routed to these Instances.

[shell]aws elb deregister-instances-from-load-balancer –load-balancer-name  ELB_NAME –instances INSTANCE_ID[/shell]

Disable availability zones for ELB
It will remove the specified availability zone from the load balancer and all the instances in this availability zone will also be removed from load balancer automatically.

[shell]aws elb disable-availability-zones-for-load-balancer –load-balancer-name  ELB_NAME –availability-zones AVAILABILITY_ZONE[/shell]

Describe all Instances health of an ELB
It will return the health state of all the instances attached to any given specific load balancer.

[shell]aws elb describe-instance-health –load-balancer-name ELB_NAME[/shell]

Describe a particular Instance health of an ELB
It will describe the health state of a particular instance attached to load balancer.

[shell]aws elb describe-instance-health –load-balancer-name  ELB_NAME –instances INSTANCE_ID[/shell]

Enable availability zones for load balancer
It enables the availability zone for any specified load balancer.

[shell]aws elb enable-availability-zones-for-load-balancer –load-balancer-name ELB_NAME –availability-zones AVAILABILITY_ZONE[/shell]

Create load balancer listeners
It creates new listener on a load balancer for a specified port.

[shell]aws elb create-load-balancer-listeners –load-balancer-name ELB_NAME  –listeners Protocol=PROTOCOL,LoadBalancerPort=PORT_NO,InstanceProtocol=PROTOCOL ,InstancePort=PORT_NO,SSLCertificateId=SSL_ID[/shell]


comments (1 “AWS Elastic Load Balancer Cookbook”)

Leave a Reply

Your email address will not be published. Required fields are marked *