| by Arround The Web | No comments

How to use the “describe-load-balancers” command in AWS CLI?

Amazon Elastic Compute Cloud (EC2) allows users to create multiple instances that provide on-demand, secure, computing services to its users. However, managing and monitoring these multiple EC2 instances can be a tedious task to do. Hence, AWS has introduced “Elastic load balancers”. The load balancer monitors the traffic patterns and then distributes the traffic accordingly across the deployed EC2 instances. Hence, it improves the health and increases the availability of the application, prevents the servers from collapsing, and enhances performance.

Learn more: An overview of different types of load balancers on AWS

Quick Outline

In this article, we will learn,

Accessing and managing these services and resources is just a few commands away via the AWS CLI. For load balancers, there are multiple commands available for creating, managing, or listing them. One such command is the “describe-load-balancers” command.

What is the “describe-load-balancers” Command in AWS CLI?

The “describe-load-balancers” command is a paginated operation that returns specific or all the load balancers for a given account. The command displays all the load balancers in the response by default if no specific name of the load balancer is provided. However, all the data is retrieved in multiple API calls to the service.

How to use the “describe-load-balancers” Command in AWS CLI?

There are no required parameters for this command. However, it accepts various optional and global parameters. Such parameters allow the user to control the output while listing the load balancers.

Syntax

The syntax of the “describe-load-balancers” command is given below:

aws elb describe-load-balancers <Options>

Options

Here is a brief description of the various options:

Options Description
–names This option is of string data type and accepts the name of the load balancer.
–load-balancer-arns Load balancers can also be listed by specifying the ARN in the “–load-balancer-arns” parameter. The ARN associated with AWS resources uniquely identifies them.
–page-size This parameter specifies the page size for displaying the details of created load balancers. The smaller the page size, the more will be API calls to the service. By specifying the page size, several items returned in the command will not be affected.
–starting-token This parameter inputs the value of the NextToken which is a string data type. The NextToken is generated in the output when there is more data to list. Providing the value of the NextToken to the –starting-token will display the remaining load balancers.
–max-items The –max-items parameter displays a limited number of load balancers in a single response. It accepts an integer value. The output of the command due to this parameter will contain the NextToken. The NextToken indicates that there is more data to list.
–cli-input-json This parameter provides multiple instructions to the resources in JSON format. The values of this option will be overwritten by the other options within the command.
–generate-cli-skeltion This parameter accepts a string value and creates a JSON skeleton or template. This template is then provided to the “cli-input-json” for specifying instructions.

Examples

There are different types of load balancers provided by AWS. For this demo, we have already created two Application Load Balancers. The examples are given below:

Example 1: How to Describe all the Load Balancers in AWS CLI?

The command given below lists all the load balancers for a given account:

aws elbv2 describe-load-balancers

Output

Example 2: How to Describe Specific Load Balancer in AWS CLI?

The following command lists a specific load balancer within the account:

aws elbv2 describe-load-balancers --names myfirstalb

Note: Replace the value myfirstalb within the command with your load balancer’s name.

Output

Example 3: How to Display a Limited Number of Load Balancers in the Output?

The –max-items option is used to display a limited number of load balancers in the response. The value for this parameter is an integer that must be between 1 to 1000:

aws elbv2 describe-load-balancers --max-items 1

Note: Replace the 1 in the –max-items with any numeric value of choice between 1 to 1000.

Output

Provide the value of NextToken to the –starting token for listing the remaining load balancers. The output will not contain any NextToken field if all the load balancers are described. The command given below demonstrates the use of the –starting-token field with the describe-load-balancers command:

aws elbv2 describe-load-balancers --starting-token <NextToken>

Note: Replace the <NextToken> with the NextToken value given in the output of your command.

Output

Example 4: How to Display Load Balancers in Different Output Formats in AWS CLI?

For displaying data in tabular format, use the following command:

aws elbv2 describe-load-balancers --output table

Note: The user can also replace the value table in the –output field with other output formats i.e., text, YAML, or JSON.

Output

Example 5: How to Describe Load Balancers without pagination in AWS CLI?

The “–no-paginate” parameter disables the pagination and retrieves all the data in a single response. The command is given as follows:

aws elbv2 describe-load-balancers --no-paginate

Output

Read more: How to Disable Pager in AWS CLI?

Example 6: How to Display Specific Details of the Load Balancers in AWS CLI?

In the output of the “describe-load-balancer” command, there are multiple details such as Security Groups, IP Addresses, Zones, Subnets, etc. The user can use the –query parameter to filter the specific details of all the load balancers by using the command given below:

aws elbv2 describe-load-balancers --query "LoadBalancers[*].[Scheme]"

Output

Similarly, the user can also filter the specific details of a particular load balancer. Currently, there are two load balancers configured within the account. By default, the array starts from 0. Therefore, to retrieve the details of the second load balancer, we have provided the “1” value within the array. This refers to the second load balancer:

aws elbv2 describe-load-balancers --query "LoadBalancers[1].[LoadBalancerArn]"

Output

Example 7: How to Describe Load Balancers in a Specific Region in AWS CLI?

Describing the load balancer within a specific region is also one of the functionality of this command. For this purpose, the –region parameter is used. Given below is the command for this functionality:

aws elbv2 describe-load-balancers --region ap-southeast-1

Note: Replace the ap-southeast-1 with the AWS region of your choice.

Output

Example 8: How to Describe the Load Balancers within a specific page size in AWS CLI?

Smaller page sizes will result in more API calls to the service for accessing the data. If the page size is specified as 1, the output will contain the “Nextmarker” value. This value is to be provided to the “–marker” option within the command to list the next load balancer within the specified page size. To describe the load balancer within a specific page size, use the following command.

aws elbv2 describe-load-balancers --page-size 100

Output

Example 9: How to Describe the Load Balancers by Specifying the ARN in AWS CLI?

To list all the load balancers based on their ARNs, provide the following command:

aws elbv2 describe-load-balancers --load-balancers-arns

Output

The following command lists specific details of a load balancer by using the ARN:

aws elbv2 describe-load-balancers --load-balancer-arns arn:aws:elasticloadbalancing:us-west-2:123456789012:loadbalancer/app/my-load-balancer/50dc6c495c0c9188

Output

That is all from this guide.

Common Exception: LoadBalancerNotFound

The following exception occurs because the user has provided the incorrect name of the load balancer:

Solution: To resolve this error, double-check the provided name and re-run the command:

That is all from this guide.

Conclusion

The describe-load-balancers command in AWS CLI returns details of a specific or all the load balancers for a given account. It accepts various options for filtering, querying, or displaying data in multiple output formats. To use this command, log in to the AWS account via AWS CLI and provide the above-mentioned commands to the terminal. This article discusses the practical implementation and various examples of listing the load balancers by using the describe-load-balancers command in AWS CLI.

Share Button

Source: linuxhint.com

Leave a Reply