AWS Elastic Load Balancer [ELB] Using CLI Part-1

AWS Elastic Load Balancer [ELB] Using CLI

ELB stands for AWS Elastic Load Balancer. ELB is used to manage load balance between multiple EC2 instances running on AWS cloud. It provides scalability and fault tolerance for application.

What Are The ELB Feature?

  • ELB is fully managed component which manage and distribute incoming application network traffic across multiple EC2 instances which can be in multiple AWS EC2 availability zones.
  • ELB can be used to load balance services in private and public IPs.
  • ELB can be terminate and process incoming secure SSL connection which improve system performance.
  • ELB provides sticky session feature to maintain user Cookie for that particular session and ensure that user session request should sent to same EC2 instance.
  • It provides Auto-Scaling that scale out AWS cloud space automatically.
  • It monitor the health of multiple EC2 instances running behind ELB and configured rules
  • It integrate with Route 53 which enables to configure our application with custom domains and global distribution of application content.

AWS support two types of load balancers:

1. Classic Load Balancer [Old Original Type]
2. Application Load Balancer [Latest Introduced Type]


types-of-load-balancer


1. Classic Load Balancer: is used to route traffic, based on applications or network level details.

It is best option for simple load balancing traffic across multiple EC2 instances where high availability, auto scaling and robust security are basic requirement of application.

It works under 4th layer of OSI model which is Transport Layer.

2. Application Load Balancer: For advanced functionality and application level support we can use Application Load Balancer.

This service operates at Application Layer and allows user to define routing rules based on content across multiple services running on one or more AWS EC2 instances.

It works under layer 7 of OSI model that is Application Layer.


How To Create Application Load Balancer:

We will need subnets and security groups to create Application Load Balancer that we can get from AWS management console which has been assigned to our EC2 instances.

>> aws elbv2 create-load-balancer --name pg-loadbal --subnets EnterMultipleSubnetsIdHere --security-group EnterSecurityGroupID

Once we execute above command, it will create application load balancer that can verify from console by navigating "Load Balancer" menu.

Please save load balancer ARN from output for future reference.


What is Target Group:

It is a groups of all targets within load balancer. Load balancer routes the requests to targets registered with target groups based on load balancers rules.

Targets could be EC2 instances or ECS contains clusters or any other services which can accept request from ELB


How To Create ELB Target Group Using CLI:

To create ELB Target Groups First we need to check status of load balancer that should be in active state.

Go to console click on menu "Load Balancer" and verify state. If state is active then only we can create Target Groups for ELB.

As we have created Application Load Balancer, so we need to use V2 operation commands to create target groups.

>> aws elbv2 create-target-group --name pggroup --protocol HTTP --port 80 --vpc-id EnterVPCIdHere

Application Load Balancer only support HTTP & HTTPS protocol where as Classic Load Balancer support some other protocols like HTTP, HTTPS, TCP, SSL and we need to mention port 80.

Also we need to specify VPC id associate with our ELB which contains same subnets which we provided while creating same ELB.

Once you press enter just save target group ARN for future reference.


How To Create / Register Target In To New Target Group:

>> aws elbv2 register-targets --target-group-arn EnterTargetGroupARNHere --targets Id=EnterTargetId

To register target in target group, we need to provide target group ARN that we just created and targets ID.

Please note Target ID can be EC2 instances id or any other services ids. In this example we are considering EC2 instance id. 

Once you execute command above it will create or register targets in that target group.


What Is The Use Of AWS Listener:

The listener is a process which checks the incoming connection requests on specific protocols and points. This protocol and port combination called as "Front End Connection". We can also define these configuration for back-end instance connections called as "Back-end Connection".

The listeners rules determine how load balancer route the request to the targets in target group.

Classic ELB Listener supports HTTP, HTTPS, TCP and SSL where as Application Load Balancer Listener supports HTTP & HTTPS only.


How To Create Listener & Check Health Of Register Target (In Our Case EC2 Instance) Using AWS CLI:

>> aws elbv2 create-listener --load-balancer-arn EnterLoadBalARNHere --protocol HTTP --port 80 --default-actions Type=forward, TargetGroupArn=EnterTargetGroupARNHere 


To create a listener we can use command "aws elbv2 create-listener" and parameters "load-balancer-arn" which we created earlier can copy from AWS management console then provide protocol and port.

We will use HTTP protocol with port 80 which is most suitable and usual combination for web application.

Then we need to set "default-actions" which means the default action to be taken by load balancer when condition and rules matched.

For example "Type=forward" that means when conditions matched, it forward the request to that defined target group.

Once you execute command you can verify this from console by clicking on Load Balancer menu.

You can see there "Listeners" tab in which you can see newly added listener. Also we can verify health of register target which we just registered.

>> aws elbv2 describe-target-health --target-group-arn EntertargetgrouoARNHere


How To Delete Load Balancer & Target Group:

>> aws elbv2 delete-load-balancer --load-balancer-arn EnterLoadBalARNHere

To delete load balancer we need to provide parameter load "load-balancer-arn" with command "aws elbv2 delete-load-balancers".

To verify go to console click on "Load Balancer" menu.

However if you click on "Target Groups" you will still see Target Group exists.

Lets See How To Delete Target Group Using CLI:

>> aws elbv2 delete-target-group --target-group-arn EnterTargetGroupARNHere

So we need to provide target group ARN to delete that specific target group.

Happy Learning AWS Services!!!! :) Still Doubts? lets put your questions in below comment box! Thanks!

Watch Video:


AWS Elastic Load Balancer [ELB] Using CLI Part-1 AWS Elastic Load Balancer [ELB] Using CLI Part-1 Reviewed by Web Technology Funda on 8:12:00 AM Rating: 5

No comments

Free! Free!Free! Subscribe to Get Free PHP (Magento) tutorial Update in Your Inbox!!! Hurry Up!!!