Contributed by: Komal Khullar
Amazon Web Services, popularly known as AWS, is a subsidiary of Amazon. AWS is an evolving cloud computing platform that gives a variety of offerings, inclusive of infrastructure as a service (IaaS), platform as a service (PaaS), and software as a service (SaaS). The cloud computing market is huge. Businesses across the world are moving to cloud platforms on account of cost savings, scalability, enhanced security, and competitive edge. There are various players in the cloud computing space, which include names like Microsoft Azure and Google Cloud Platform (GCP). AWS is by far the leader and major player in cloud computing and continues to dominate the market.
AWS is a secure cloud services platform that provides compute power, database storage, content delivery, and other functionalities to help businesses grow and transform.
AWS offers an interface to its users through AWS Management Console and Command Line Interface, CLI. AWS management console is a web application that allows its users to view, monitor, and manage resources offered by AWS. The Command Line Interface is another tool to manage AWS services. The core functionality provided by the Command Line Interface is the same as that of the console. However, there is an option for additional commands. The endeavor here is to understand more about Amazon’s Command Line Interface, mostly referred to as AWS CLI.
This article will cover the AWS CLI in detail and broadly touch on mentioned points at length.
- What is a Command Line Interface?
- What is an AWS Command Line Interface?
- Benefits of Command Line Interface
- Installation and configuration of the CLI
- How can CLI be put to use?
What is a Command Line Interface?
Command Line Interface, i.e., CLI, is a command-line program that accepts the text input to execute the functions of an operating system. For example, every CLI has a command prompt that is displayed when the interface is ready to accept a command. The Command-Line Interface allows the user to create and delete files, run programs and navigate through folders and files. Cloud computing relies on CLI largely along with the console. Developers use AWS CLI for interacting with the virtual machines, launching instances, running applications in the cloud, and for other cloud transactions.
What is an AWS Command Line Interface?
As the name prominently suggests, Command Line Interface is an interface that allows its users to operate from the command line. The AWS instruction Interface is a tool to manage AWS services. By simple download and configuration of the CLI, a user can manually control the AWS services or automate them by writing scripts. It is a user-friendly way of interacting with the system using a graphical user interface knows as GUI.
Benefits of Command Line Interface (CLI)
One of the most important benefits of Command Line Interface is its ability to save a large amount of time. The below-stated factors contribute to the savings in the form of time. We will discuss these benefits in some detail for better understanding.
- Supportive of all Amazon Web Services- Before the introduction of CLI, users needed dedicated tools to launch instances like those of EC2. For other services of AWS, this option did not work well for the users. Command Line Interface (CLI) allows the user to have a single tool to control all services of AWS.
- Easy installation- Earlier multiple environment variables were required for installing CLI. It is effortless, simple to install a Command Line Interface.
- Allows scripting and automation- CLI allows to automate the entire process of managing AWS services through writing scripts. Shell scripts allow and make it easy for the users to automate the complete cloud infrastructure. CLI allows automating of common and repetitive administrative tasks in AWS. Automation of tasks can assist the developers and free them from the need to sign in to the AWS management console.
- Saves Time- One of the most important benefits of CLI is that it saves an enormous amount of time. AWS CLI offers great functionality and speed, adding to the benefit of saving time.
Installation and configuration of the Command Line Interface (CLI)
Installation of CLI:
The AWS CLI comes pre-installed on Amazon Linux. However, we can install it on Windows, macOS, Linux, and Docker containers. The latest and most recent version available for AWS CLI is version 2, supporting all the latest features. Amazon CLI version 2 has pre-built binaries for Windows, macOS, and Linux. With this version 2, the user no longer needs an installation of Python, the programming language. Users can install and work on version 1, too, since AWS still supports it, but that would be outdated, so installing version 2 is highly recommended. The user, in any case, must either have version 2 or version 1 installed in his system. To check the version you have installed, use the below prompt :
C:\> aws –version
aws-cli/2.1.29 Python/3.7.4 Windows/10 botocore/2.0.0
Certain pre-requisites were earlier required to be met for the CLI to be installed. These included the checks for having Python 2 version 2.7 or later, or Python 3 version 3.6 or later installed, along with ensuring that relevant operating system viz Windows, macOS, Linux is in place. In the recent development introduced in the year 2020, the user no longer needs to have Python installed to run and use AWS CLI. Also, with this latest development of the last year, the pre-checks for Python versions, packages, and virtual environments are not to be done. AWS provides a 64-bit windows installer for Windows and a .pkg installer for the macOS and Linux installer for Linux.
Amazon’s documentation for installation of Command Line Interface explains its installation using:
- Pip install
Pip is the easiest way to install a CLI and keep it up-to-date.
Users with Pip install can simply run the below command for installation :
$ pip install —upgrade – user awscli
- Virtual environment
It is a command-line application. It modifies environment variables in a shell to create an isolated python environment. The configuration of the environment variables can overwrite the default values of the command line.
- Bundled installer
CLI can be installed using the bundled installer provided by AWS. Bundled installer simplifies the process of CLI installation to a great extent.
AWS instruction interface (AWS CLI) interaction uses certain settings to interact with AWS. The configuration of these settings is imperative for AWS CLI installation.
Configuration of CLI:
The command aws configure is the fastest means to install a Command Line Interface. The command will look like what is demonstrated below
$ aws configure
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-west-2
Default output format [None]: JSON
The CLI would require these four pieces of information for quick configuration.
- Access key ID and Secret Access Key- can be created from the AWS management console. The combination of access key and secret access key is used to make requests to AWS. The credentials created will look like below:
Access key ID: AKIAIOSFODNN7EXAMPLE
Secret access key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
It is important to note that the access and secret access key is displayed only once. If these keys are lost, then there is no way to retrieve them. Hence, it is important to save the details of the access and secret key safely and securely. AWS does not retain any copies of these keys for security purposes. In case of loss of access and secret key, new keys have to be recreated. Access keys are associated with AWS CLI to ensure that all API requests made to AWS are signed in with a digital signature.
- AWS region- refers to the default location to whose servers the user’s request will be sent. AWS region must be set for the use of CLI, or a default region must be used. A region is defined as a geographical location that is closest to the user.
- Output format- The default output format specifies how the result is to be formatted. In the absence of any format specification, the output format is JSON. Other output formats available are YAML, YAML-stream, text, and table.
- JSON- default format and output are formatted as JSON string
- YAML- this output format is available in version 2 of AWS CLI, and output is formatted in YAML string
- YAML-stream- this output format is also available in version 2 of AWS CLI, and output is streamed and formatted in YAML-string. Streaming allows faster handling of large data types
- Text- output is formatted as multiple lines of tab-separated string values
- Table- these are not very useful programmatically. However, here output is formatted as a table using characters +|- to make cell borders. The table format is much easier to read and is quite user friendly
Once the AWS CLI has been installed and configured, the user can take further steps to manage, script, and put the AWS service in use. AWS provides detailed AWS CLI documentation references and guides on their website for immediate use.
How can CLI be put to use?
To enable the successful use of AWS Command Line Interface, an outbound connection on TCP port 443 must be made by the user. CLI sends requests to AWS services using HTTP on TCP port 443 by default.
AWS management console can be used to launch an instance. If multiple instances of different variations have to be launched, it can be very time-consuming, involving a lot of time and effort. The same task of launching an instance, known as an EC2 instance, can be done using the AWS CLI. Multiple commands have to be typed when using a Command Line Interface, which may seem overwhelming initially. However, these various commands can be combined into one and be saved in the form of a script. This script allows the user to save re-writing the commands and instead run a script to perform a repetitive task.
AWS CLI can be used to access various AWS services like below:
- Identity and Access Management (IAM)
- Amazon Elastic Cloud (EC2)
- Amazon Simple Storage Service (S3)
- Dynamo DB (database)
For explanation and greater insight into using the CLI, we will use the example of creating IAM users and groups via the command-line interface. The below commands will be used to create an IAM group and add a new user to it
- Group creation using create-group command
$ aws iam create-group --group-name MyIamGroup
{
"Group": {
"GroupName": "MyIamGroup",
"CreateDate": "2018-12-14T03:03:52.834Z",
"GroupId": "AGPAJNUJ2W4IJVEXAMPLE",
"Arn": "arn:aws:iam::123456789012:group/MyIamGroup",
"Path": "/"
}
}
- User creation using create-user command
$ aws iam create-user --user-name MyUser
{
"User": {
"UserName": "MyUser",
"Path": "/",
"CreateDate": "2018-12-14T03:13:02.581Z",
"UserId": "AIDAJY2PE5XUZ4EXAMPLE",
"Arn": "arn:aws:iam::123456789012:user/MyUser"
}
}
- Command to add a user to the group, use add-user-to-group
$ aws iam add-user-to-group --user-name MyUser --group-name MyIamGroup
- To verify that the correct user is added to the group below command to be used
$ aws iam get-group --group-name MyIamGroup
{
"Group": {
"GroupName": "MyIamGroup",
"CreateDate": "2018-12-14T03:03:52Z",
"GroupId": "AGPAJNUJ2W4IJVEXAMPLE",
"Arn": "arn:aws:iam::123456789012:group/MyIamGroup",
"Path": "/"
},
"Users": [
{
"UserName": "MyUser",
"Path": "/",
"CreateDate": "2018-12-14T03:13:02Z",
"UserId": "AIDAJY2PE5XUZ4EXAMPLE",
"Arn": "arn:aws:iam::123456789012:user/MyUser"
}
],
"IsTruncated": "false"
}
The above command-line interface example is one simple demonstration of how CLI can be used. However, CLI can be used for much more.
The Amazon Web services CLI is a powerful tool that helps manage cloud services very effectively. It allows the creation of simple and fast scripts and hence a convenient tool for cloud development. Command Line interface unlocks new avenues in the user’s programming ability.
In this blog, we have explored the Command Line Interface of AWS. For decades, developers and researchers worldwide are using the command-line interface to build, execute and deploy software. This blog is a place to go for basic information about AWS-CLI and covers the topics to build the reader’s understanding of this subject.
Do check out our post-graduate program in cloud computing to accelerate your career in the field of Cloud Computing.