Today's Offer - AWS Certification Training - Enroll at Flat 10% Off.

- AWS Blogs -

What is AWS CLI? How to Install AWS CLI?

Amazon Web Services is one of the top market leaders in the era of cloud computing. It helps in the different sectors of technology like gaming, data processing, data warehousing, development, etc. Amazon’s Command Line interface is also the top eye-catcher of the browser console. Using the command line interface, a developer can type a command to designate a profile, region, or output format that is different than default configurations. Today, we’ll discuss the basic terminology associated with AWS CLI, its usage, installation, and few of the AWS CLI commands. Let move further!

What is AWS CLI?

AWS CLIThe AWS CLI is an open-source tool that enables you to communicate with AWS services using commands in your command-line shell. You may start using the functionality of AWS CLI with the minimal configuration only. The AWS CLI manages your AWS services from a terminal session on your own client and allows you to control and configure multiple AWS services.

AWS CLI Terminology

AWS CLI Terminology

  • Linux Shells: Make use of common shell programs such as bash, zsh, and tsch to run commands in Linux, Mac, or Unix
  • Windows Command Line: To run commands on Windows OS, PowerShell or at the command prompt of Windows
  • Remotely: You can run commands on Amazon Elastic Compute Cloud (Amazon EC2) instances through a remote terminal such as PuTTY or SSH, or with AWS System Manager

Uses of AWS CLI

  • Installation of AWS CLI is quick, simple, and standardized
  • Using command liner saves plenty of your time in many occasions
  • AWS CLI provides you the ability to automate the entire process of controlling and managing AWS services

Installing AWS CLI

  • Using pip
  • Using a virtual environment
  • Using a bundled installer

Using pip

Pip is the primary distribution method for the AWS CLI on Linux, Windows, and macOS. This is said to be a package manager for Python that provides an easy way to install, upgrade, and remove Python packages and their dependencies.

Installing the current AWS CLI Version

The AWS CLI is updated frequently with the support for new services and commands. If you have already installed pip and a supported version of Python in your system, then you can install the AWS CLI by using the following command. If you have installed Python version 3+, then it is recommended to use ‘pip3 command’.

$ pip3 install awscli --upgrade --user

The --upgrade option notifies the pip3 to upgrade any requirements that are already installed.

The --user option notifies pip3 to install the program to a subdirectory of your user directory to avoid modifying libraries used by your operating system.

We recommend that you regularly check to see if there is a new version of the AWS CLI and upgrade to it when you can. You can use pip list -o command to check which packages are "outdated':


$ aws --version was-cli/1.16.170 Python/3.7.3 Linux/4.14.123-111.109.amzn2.x86_64 botocore/1.12.160 
$ pip3 list -o Package Version Latest Type ---------- -------- -------- ----- 
awscli 1.16.170 1.16.198 wheel botocore 1.12.160 1.12.188 wheel

Using a virtual environment

If you confront issues while installing the AWS CLI with pip3, you can install the AWS CLI in a virtual environment to isolate the tool and its dependencies. Or you can use a different version of Python than you normally do.

For offline or automated installations on Linux, macOS, or Unix, try the bundled installer. The bundled installer incorporates the AWS CLI, its dependencies, and a shell script that installs for you.

On Windows, you can also use the MSI installer. Both of these methods simplify the initial installation. However, the tradeoff is that it's more difficult to upgrade when a new version of the AWS CLI is released.

You can verify the AWS CLI installed correctly by running aws --version command.


$ aws --version aws-cli/1.16.116 Python/3.6.8 Linux/4.14.77-81.59-amzn2.x86_64 botocore/1.12.106

Upgrading the Latest Version of the AWS CLI

The AWS CLI is updated frequently to add support for new services and commands. If you want to update the latest version of the AWS CLI, run the install command again.

$ pip3 install awscli --upgrade –user

Uninstalling the AWS CLI

If you need to uninstall the AWS CLI, then use pip uninstall.

$ pip3 uninstall awscli

If you don't have Python and pip, use the procedure for your environment.

Using a bundled installer

You can perform the following steps from the command line to install the AWS CLI using the bundled installer:

  • To install the AWS CLI using the bundled installer, first, download the AWS CLI Bundled Installer: $ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
  • Unzip the package (If you don't have to unzip, use your favorite package manager to install it or an equivalent): $ unzip awscli-bundle.zip
  • Run the install program: $ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

Installing AWS CLI in Windows

The installation of AWS Command Line Interface (AWS CLI) can be done on Windows by using a standalone installer or pip, which is a package manager for Python. The AWS CLI is supported on Windows XP or later. For the users of Windows, the MSI installation package can be used as a convenient way to install the AWS CLI without installing any other prerequisites. When you find the release of updates, then you have to repeat the installation process to get the latest version of the AWS CLI. To update frequently, it would be better to consider using pip for easier updates.

To install the AWS CLI using the MSI installer

  • Download the appropriate MSI installer.
    • The download 64-bit version of AWS CLI MSI installer for Windows
    • The download 32-bit version of AWS CLI MSI installer for Windows
    • Download AWS CLI setup file (includes both the 32-bit and 64-bit MSI installers and will automatically install the correct version)

Note: The MSI installer for the AWS CLI doesn't work with Windows Server 2008 (version 6.0.6002). You have to use pip to install with this version of Windows Server

  • Run the downloaded MSI installer or the setup file
  • Follow the onscreen instructions.

By default, the CLI installs to C:\Program Files\Amazon\AWSCLI (64-bit version) or C:\Program Files (x86)\Amazon\AWSCLI (32-bit version). To confirm the installation, use the aws --version command at a command prompt (open the Start menu and search for cmd to start a command prompt).


C:\> aws --version
aws-cli/1.16.116 Python/3.6.8 Windows/10 botocore/1.12.106

Don't attach the prompt symbol (C:\>, shown above) when you type a command. These are attached in program listings to differentiate commands that you type from output returned by the CLI.

If Windows is unable to find the program, you might need to close and reopen the command prompt to refresh the path, or add the installation directory to your PATH environment variable manually.

Updating an MSI Installation

The AWS CLI is updated regularly. If you want to update your previous AWS CLI to the latest version, download and run the MSI installer again, as described previously.

Uninstalling the AWS CLI

To uninstall the AWS CLI from the system, open Control Panel, and then choose Programs and Features. Select AWS Command Line Interface, and then choose Uninstall to launch the uninstaller. Confirm the uninstallation of AWS CLI when you're prompted.

Read: AWS, Linode & DigitalOcean Compared- All you should know

You can also originate the Programs and Features program from the command line with the following command:

C:\> appwiz.cpl

Installing the AWS CLI on Linux

The installation of AWS CLI and its dependencies on most Linux distributions are performed by using pip, a package manager for Python.

The AWS CLI package can be availed through various repositories for other package managers like apt and yum, but you cannot get the latest version unless you get it from pip or use the bundled installer.

Run pip -- version to see if your version of Linux already includes Python and pip. It is recommended to have Python version 3+ installed in your system so that you use the pip3 command.

$ pip3 --version

If you don't already have pip installed, check which version of Python is installed in your system.

$ python --version

or

$ python3 --version

Installing the AWS CLI on MAC OS

The paths that show up depend on which method you used to install the AWS CLI.

Typical paths include:

  • Python 3 and pip3 C:\Program Files\Python37\Scripts\
  • Python 3 and pip3 --user option on earlier versions of Windows %USERPROFILE%\AppData \Local\Programs\Python\Python37\Scripts
  • Python 3 and pip3 --user option on Windows 10 %USERPROFILE%\AppData\Roaming\Python \Python37\Scripts
  • MSI installer (64-bit) C:\Program Files\Amazon\AWSCLI\bin
  • MSI installer (32-bit) C:\Program Files (x86)\Amazon\AWSCLI\bin

 Note: Folder names that include version numbers can vary. The examples above reflect the use of Python version 3.7. Replace as needed with the version number you are using.

To modify your PATH variable (Windows)

  1. Press the Windows key and enter environment variables.
  2. Choose Edit environment variables for your account.
  3. Choose PATH, and then choose Edit.
  4. Add the path to the Variable value For example: C:\new\path
  5. Choose OK twice to apply the new settings.
  6. Close any running command prompts and reopen the command prompt window.
  7. The recommended way to install the AWS Command Line Interface (AWS CLI) on macOS is to use the bundled installer. The bundled installer includes all dependencies and you can use it offline.

Important: The bundled installer doesn't support installing to the paths that contain spaces.

Prerequisites

  • Python 2 version 2.6.5+ or Python 3 version 3.3+
  • Check your Python installation :$ python --version

If you have not installed Python in your system or, if you want to install a different version of Python, then follow the procedure of Installation of the AWS CLI on Linux.

How to use AWS CLI?

After walking through the AWS CLI user guide and performing installation and configuration of the tool, you can begin making calls to your AWS services from the command line.


$ aws ec2 describe-instances
$ aws ec2 start-instances --instance-ids i-1348636c
$ aws sns publish --topic-arn arn:aws:sns:us-east-1:546419318123:OperationsError --message "Script Failure"
$ aws sqs receive-message --queue-url https://queue.amazonaws.com/546419318123/Test

You can take help from the command line to view the supported services,

$ aws help

the operations for a service,

$ aws autoscaling help

and the parameters for a service operation.

$ aws autoscaling create-auto-scaling-group help

AWS CLI Best Practices and Commands


list-commands
[--command-id <value>]
[--instance-id <value>]
[--filters <value>]
[--cli-input-json <value>]
[--starting-token <value>]
[--page-size <value>]
[--max-items <value>]
[--generate-cli-skeleton <value>]

Options

--command-id (string)

(Optional) If provided, lists only the specified command.

--instance-id (string)

(Optional) Lists commands issued against this instance ID.

--filters (list)

(Optional) One or more filters. Use filters to return a more specific list of results.

Shorthand Syntax:

Read: What is AWS Fargate? Amazon EC2 vs. Amazon Fargate

key=string,value=string ...

--cli-input-json (string)

You can use the service operation based on the JSON string provided which follows the format provided by --generate-cli-skeleton.

--starting-token (string)

A token to specify where to start paginating. This is the NextToken from a previously truncated response.

--page-size (integer)

The size of each page to get in the AWS service call. There is no effect on the number of items returned in the command's output by using this command. This command can set a smaller page size results in more calls to the AWS service by retrieving fewer items in each call. This can help in the prevention of AWS service calls from timing out.

--max-items (integer)

It is the total number of items to return in the command's output. If the total number of items available is more than the value specified, then the NextToken is provided in the command's output.

--generate-cli-skeleton (string)

It prints a JSON skeleton to standard output without sending an API request. If there is no value or the value input, then it prints a sample input JSON that can be used as an argument for --cli-input-json.

Key -> (string)

It is the user-defined criteria for sending commands that target instances that meet the criteria.

Values -> (list)

It is a user-defined criteria that maps to Key. For example, if you have specified tag: ServerRole, you could specify value:WebServer to run a command on instances that include Amazon EC2 tags of ServerRole,WebServer .

(string)

RequestedDateTime -> (timestamp)

The date and time the command was requested.

Status -> (string)

The status of the command.

StatusDetails -> (string)

A detailed status of the command execution. StatusDetails includes more information than Status because it includes states resulting from error and concurrency control parameters. StatusDetails can show different results than Status.

StatusDetails can be one of the following values:

  • Pending: The command has not been sent to any instances
  • In Progress: The command has been sent to at least one instance but has not reached a final state on all instances
  • Success: The command successfully ran on all invocations. This is a terminal state
  • Delivery Timed Out: The value of MaxErrors or more command invocations shows the status of Delivery Timed Out. This is a terminal state
  • Execution Timed Out: The value of MaxErrors or more command invocations shows a status of Execution Timed Out. This is a terminal state
  • Failed: The value of MaxErrors or more command invocations shows a status of Failed. This is a terminal state
  • Incomplete: The command was attempted on all instances, and one or more invocations does not have a value of Success, but not enough invocations failed for the status to be Failed. This is a terminal state.
  • Canceled: The command was terminated before it was completed. This is a terminal state
  • Rate Exceeded: The number of instances targeted by the command exceeded the account limit for pending invocations. The system has cancelled the command before running it on any instance. This is a terminal state.

OutputS3Region -> (string)

(Deprecated) You can no longer specify this parameter as the system ignores it. Instead, Systems Manager automatically determines the Amazon S3 bucket region.

OutputS3BucketName -> (string)

It is the S3 bucket where the responses to the command executions should be stored. This was requested when issuing the command.

OutputS3KeyPrefix -> (string)

It is the S3 directory path inside the bucket where the responses to the command executions should be stored. This was requested when issuing the command.

MaxConcurrency -> (string)

It is the maximum number of instances that are allowed to run the command at the same time. You can specify a number of instances, such as 10, or a percentage of instances, such as 10%. The default value is 50.

MaxErrors -> (string)

Read: Difference between AWS Inspector and AWS Trusted Advisor

It is the maximum number of errors allowed before the system stops sending the command to additional targets. You can specify a number of errors, such as 10, or a percentage or errors, such as 10%. The default value is 0.

MaxErrors -> (string)

It is the maximum number of errors allowed before the system stops sending the command to additional targets. You can specify a number of errors, such as 10, or a percentage or errors, such as 10%. The default value is 0.

TargetCount -> (integer)

It is the number of targets for the command.

CompletedCount -> (integer)

It is the number of targets for which the command invocation reached a terminal state. Terminal states include the following: Success, Failed, Execution Timed Out, Delivery Timed Out, Canceled, Terminated, or Undeliverable.

ErrorCount -> (integer)

It is the number of targets for which the status is Failed or Execution Timed Out.

DeliveryTimedOutCount -> (integer)

It is the number of targets for which the status is Delivery Timed Out.

ServiceRole -> (string)

It is the IAM service role that Run Command uses to act on your behalf when sending notifications about command status changes.

NotificationConfig -> (structure)

Configurations for sending notifications about command status changes.

NotificationArn -> (string)

It is an Amazon Resource Name (ARN) for an Amazon Simple Notification Service (Amazon SNS) topic. Run Command pushes notifications about command status changes to this topic.

NotificationEvents -> (list)

These are the different events for which you can receive notifications. These events include the following: All (events), InProgress, Success, TimedOut, Cancelled, Failed.

NotificationType -> (string)

The command receives a notification when the status of a command changes. The invocation of this command is to send to multiple instances and receive a notification on a per-instance basis when the status of a command changes.

CloudWatchOutputConfig -> (structure)

The CloudWatch Logs to the information where you want Systems Manager to send the command output.

CloudWatchLogGroupName -> (string)

The name of the CloudWatch log group where you want to send command output. If you don't specify a group name, Systems Manager automatically creates a log group for you. The log group uses the following naming format: aws/ssm/SystemsManagerDocumentName .

CloudWatchOutputEnabled -> (boolean)

This command sanctions Systems Manager to send command output to CloudWatch Logs.

NextToken -> (string)

(Optional) This is the token for the next set of items to return.

Conclusion

AWS is a secure cloud service platform that offers infrastructure services to the developers. On the other hand, AWS CLI is like honey for the bee that controls all those services together into a simple command-line interface and eases the task of developer. Now, experiment these commands and check if you get the desired results!
If you have any questions for us? Feel free to ask or talk to our counselor; we’ll get back to you!


    Janbask Training

    JanBask Training is a leading Global Online Training Provider through Live Sessions. The Live classes provide a blended approach of hands on experience along with theoretical knowledge which is driven by certified professionals.


Trending Courses

AWS

  • AWS & Fundamentals of Linux
  • Amazon Simple Storage Service
  • Elastic Compute Cloud
  • Databases Overview & Amazon Route 53

Upcoming Class

2 days 14 Dec 2019

DevOps

  • Intro to DevOps
  • GIT and Maven
  • Jenkins & Ansible
  • Docker and Cloud Computing

Upcoming Class

3 days 15 Dec 2019

Data Science

  • Data Science Introduction
  • Hadoop and Spark Overview
  • Python & Intro to R Programming
  • Machine Learning

Upcoming Class

3 days 15 Dec 2019

Hadoop

  • Architecture, HDFS & MapReduce
  • Unix Shell & Apache Pig Installation
  • HIVE Installation & User-Defined Functions
  • SQOOP & Hbase Installation

Upcoming Class

4 days 16 Dec 2019

Salesforce

  • Salesforce Configuration Introduction
  • Security & Automation Process
  • Sales & Service Cloud
  • Apex Programming, SOQL & SOSL

Upcoming Class

-1 day 11 Dec 2019

QA

  • Introduction and Software Testing
  • Software Test Life Cycle
  • Automation Testing and API Testing
  • Selenium framework development using Testing

Upcoming Class

8 days 20 Dec 2019

Business Analyst

  • BA & Stakeholders Overview
  • BPMN, Requirement Elicitation
  • BA Tools & Design Documents
  • Enterprise Analysis, Agile & Scrum

Upcoming Class

4 days 16 Dec 2019

SQL Server

  • Introduction & Database Query
  • Programming, Indexes & System Functions
  • SSIS Package Development Procedures
  • SSRS Report Design

Upcoming Class

4 days 16 Dec 2019

Comments

Search Posts

Reset

Receive Latest Materials and Offers on AWS Course

Interviews