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.
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
Add health checks to the ELB
It specifies the ELB health check settings used to verify the instance health state.
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
Show All ELB
It returns the detailed information about all the ELBs created in your account.
aws elb describe-load-balancers
Show a particular ELB
It returns detailed information about a particular mentioned ELB.
aws elb describe-load-balancers --load-balancer-names ELB_NAME
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.
aws elb apply-security-groups-to-load-balancer --load-balancer-name ELB_NAME --security-groups SECURITY_GROUP_ID
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.
aws elb register-instances-with-load-balancer --load-balancer-name ELB_NAME --instances INSTANCE_ID
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.
aws elb attach-load-balancer-to-subnets --load-balancer-name ELB_NAME --subnets SUBNET_ID
Delete an ELB
By using below mentioned command, one can easily delete the given load balancer.
aws elb delete-load-balancer --load-balancer-name ELB_NAME
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.
aws elb set-load-balancer-listener-ssl-certificate --load-balancer-name ELB_NAME --load-balancer-port PORT_NO --ssl-certificate-id SSL_ID
Delete port from ELB
It will delete the listener from ELB for given port number.
aws elb delete-load-balancer-listeners --load-balancer-name ELB_NAME --load-balancer-ports PORT_NO
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.
aws elb detach-load-balancer-from-subnets --load-balancer-name ELB_NAME --subnets SUBNET_ID
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.
aws elb deregister-instances-from-load-balancer --load-balancer-name ELB_NAME --instances INSTANCE_ID
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.
aws elb disable-availability-zones-for-load-balancer --load-balancer-name ELB_NAME --availability-zones AVAILABILITY_ZONE
Describe all Instances health of an ELB
It will return the health state of all the instances attached to any given specific load balancer.
aws elb describe-instance-health --load-balancer-name ELB_NAME
Describe a particular Instance health of an ELB
It will describe the health state of a particular instance attached to load balancer.
aws elb describe-instance-health --load-balancer-name ELB_NAME --instances INSTANCE_ID
Enable availability zones for load balancer
It enables the availability zone for any specified load balancer.
aws elb enable-availability-zones-for-load-balancer --load-balancer-name ELB_NAME --availability-zones AVAILABILITY_ZONE
Create load balancer listeners
It creates new listener on a load balancer for a specified port.
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