What is AWS Command Line Interface (AWS CLI)

What is AWS Command Line Interface (AWS CLI) and How to install AWS CLI

AWS Command Line Interface (AWS CLI) is a command-line tool that allows you to interact with AWS services from a script in your command-line shell. By simply configuring the AWS CLI, it enables you to run commands from your terminal program that provide functionality similar to that provided by the browser-based AWS Management Console:

  • Linux shells – In Linux or MacOS, you can run commands using the bash, zsh, or tcsh shell programs.
  • Windows command line – Windows command prompt or PowerShell can be used to execute commands.
  • Remotely – Commands can be run on Amazon Elastic Compute Cloud (Amazon EC2) instances using a remote terminal application, such as PuTTY or SSH, or AWS Systems Manager.

New AWS IaaS features and services are provided with full AWS Management Console functionality within 180 days or at launch through the API and CLI. AWS IaaS administration, management, and access functions in the AWS Management Console are accessible through the AWS API and AWS CLI.

Access to public APIs of AWS services can be obtained directly with the AWS CLI. With the AWS CLI, you can explore what service has to offer and manage your resources with shell scripts. The AWS CLI can be customized to support more advanced commands tailored to a service with a complex API. Customizations can offer higher-level commands that can simplify the use of a service with a complex API.

About AWS CLI version 2

AWS CLI version 2 supports all of the latest features of the AWS CLI, which is the most recent major version of the AWS CLI. It’s impossible to access certain features from version 1 due to limitations introduced in version 2. A few “breaking” changes have been made from version 1 to version 2. If you have changed your scripts, you might need to adjust them.

Installing or updating the latest version of the AWS CLI

Installing and updating the latest release of the Amazon Web Services Command Line Interface (AWS CLI) on supported operating systems is discussed in this topic. The AWS CLI change notes are available on GitHub for information on the latest releases of AWS CLI.

AWS CLI installation instructions:

Linux

Installation requirements
  • The package must be able to be unzipped or extracted. If your operating system doesn’t offer that option, you may need to use an alternative unzip command.
  • In the AWS CLI, glibc, Groff, and less are used. All of these components are included in the most widespread Linux distributions.
  • We support Amazon Linux 1, Amazon Linux 2, and Linux ARM 64-bit versions of CentOS, Fedora, Ubuntu, and Amazon Linux CLI.
  • AWS doesn’t offer any guarantees that third-party repositories contain the latest AWS CLI since AWS doesn’t maintain them.
Install or update the AWS CLI

These steps will help you install the AWS CLI from the command line. Based on the type of Linux you’re using, we provide a copy-and-paste form that’s easy to follow. See the descriptions of each line in the steps following.

ALSO READ  AWS - Difference between Containers (Kubernetes)  and Serverless (Lambda) 

Linux x86(64-bit)

$ curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install

Linux ARM

curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install
  1. To get the installation file, please follow these steps:

Linux x86(64-bit)

  • Use the curl command – It specifies the file’s name that the downloaded package will be written to when -o is used. For example, the following command saves the downloaded file with the local name awscliv2.zip in the current directory.
  • $ curl “https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip” -o “awscliv2.zip”
  • Downloading from the URL – Here is the URL you’ll need to use with your browser to download the installer: https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip

(Optional) Follow the instructions below to verify your downloaded installation file’s integrity and authenticity before unpacking it (Optional). Verifying the integrity of your downloaded zip file.

Linux ARM

  • Use the curl command – It specifies the name of the file that the downloaded package will be written to when -o is used. For example, the following command saves the downloaded file with the local name awscliv2.zip in the current directory.
$ curl "https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip" -o "awscliv2.zip"
  • Downloading from the URL – Here is the URL you’ll need to use with your browser to download the installer: https://awscli.amazonaws.com/awscli-exe-linux-aarch64.zip

(Optional) Follow the instructions below to verify your downloaded installation file’s integrity and authenticity before unpacking it (Optional). Verifying the integrity of your downloaded zip file.

  • Unzip the installer. Alternatively, use a command equivalent if your Linux distribution does not have a built-in unzip command. The following example is created by unzipping the package and creating an AWS directory under the current directory.
unzip awscliv2.zip
  • Run the install program. In the newly unzipped aws directory, call the install command in the file titled install. Files are automatically installed into /usr/local/AWS-CLI, and symbolic links are created in /usr/local/bin. The command includes sudo to grant write permissions to those directories.
sudo ./aws/install

In case you specify directories for which you already have to write access, you can make the installation without sudo. For details relating to the installation location, follow these instructions:

  • It would be best to remove all white spaces and space characters from the paths you provide to the -I and -b parameters. The installation will fail if there are spaces in the paths.
  • –install-dir or -i – This option specifies the directory to copy all of the files to. /usr/local/AWS-CLI is the default value.
  • The -bin-dir option instructs aws to link to the aws file in the specified path from the main aws program in the install directory. It is required that access to the specified directory is granted. In this case, you won’t need to add the install directory to the user’s $PATH variable since there is already a link to it in your path.
  •  /usr/local/bin is the default value.
./aws/install -i /usr/local/aws-cli -b /usr/local/bin
  • Use the following command to confirm the installation.
aws --version aws-cli/2.4.5 Python/3.8.8 Linux/4.14.133-113.105.amzn2.x86_64 botocore/2.4.5

Adding the AWS CLI to your path may be the solution if the aws command cannot be found. Please restart your terminal if necessary.

macOS

Installation requirements

  • Mac OS X versions that Apple supports with the AWS CLI are supported.
  • AWS does not maintain the AWS CLI, so you cannot be sure that the third-party repository contains the latest version.

Install or update the AWS CLI

The same installation method you used to install your current version should be used to update the latest version. Below is a list of methods for installing the AWS CLI on macOS.

ALSO READ  Optimize Your Software with Observability in Development and Testing

GUI Installer

Using your browser and the standard macOS user interface, follow the steps below to install the latest version of the AWS CLI.

  1. To download (pkg) file for macOS, please visit this URL: https://awscli.amazonaws.com/AWSCLIV2.pkg
  2. Once you have downloaded the file, launch it and read the instructions. There are several ways to install the AWS CLI, including:
  3. For all users on the computer (requires sudo)
    1. /usr/local/aws-cli is recommended as the default install folder, although you can choose any folder.
    2. During installation, a symlink is automatically created at /usr/local/bin/aws that points to the main program in the installation directory you selected.
  4. For only the current user (it doesn’t require sudo)
    1. The installation can be performed in any folder you have permission to write to.
    2. The following commands at the command prompt need to be run after the installation finishes in order to create a symlink that points to the aws and the AWS_completer programs in your $PATH due to the standard permissions of the current user. By specifying that folder as a target’s path, you can run the following command without having to use sudo if your $PATH includes a folder to which you can write. If your $PATH doesn’t have a writable folder, your commands must be run by sudo to allow access to the specified folder. Symlinks by default are located in /usr/local/bin/.
  5. sudo ln -s /folder/installed/aws-cli/aws /usr/local/bin/aws
  6. sudo ln -s /folder/installed/aws-cli/aws_completer /usr/local/bin/aws_completer
  7. Here are some commands to make sure your shell can locate and run the aws command from your $PATH.
 $ which aws /usr/local/bin/aws
$ aws --version aws-cli/2.4.5 Python/3.8.8 Darwin/18.7.0 botocore/2.4.5

Adding the AWS CLI to your path may be the solution if the aws command cannot be found. Please restart your terminal if necessary.

Command-line installer – All user

Install the AWS CLI for all computers on your network if you have sudo permissions. All steps are grouped together in one easy-to-copy and paste group. Follow the steps below for how to copy each step.

$ curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg" $ sudo installer -pkg AWSCLIV2.pkg -target /
  1. Utilize the curl command to download the file. The file name specified by the -o option specifies the location where the downloaded package will be saved. In the case described here, the current folder is AWSCLIV2.pkg.
$ curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
  • Install macOS using the downloaded .pkg file. The macOS installer program will ask you for the source file. The -pkg parameter specifies the package to install, the -target parameter details the drive where the package will be installed, and the -target parameter specifies which package to install. As a result, a symlink is created in /usr/local/bin and the files get installed to /usr/local/aws-cli. For those folders to have write access, sudo must be included in the command.
$ sudo installer -pkg ./AWSCLIV2.pkg -target /
  • /var/log/install.log is the place where debug logs are stored after the installation has been completed.
  • Use the following command to check whether the shell is able to find and execute the aws command from your $PATH.
$ which aws /usr/local/bin/aws
$ aws --version aws-cli/2.4.5 Python/3.8.8 Darwin/18.7.0 botocore/2.4.5

Adding the AWS CLI to your path may be the solution if the aws command cannot be found. Please restart your terminal if necessary.

ALSO READ  AWS Route 53 Interview Guide: Boost Your Chances of Success

Command Line – Current User

  1. It is necessary to create a file with any name to specify which folder the AWS CLI is installed. It’s an XML file, which looks like the example above. Leaving all values as shown, you will need to change the path /Users/myusername in line 9 to the path to the folder to which you wish to install the AWS CLI. If the folder doesn’t exist, then the command will fail. An example of XML in the following file, named choices.xml, specifies that the installer should install the AWS CLI in the folder /Users/myusername, which creates a folder named aws-cli.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  <array>
    <dict>
      <key>choiceAttribute</key>
      <string>customLocation</string>
      <key>attributeSetting</key>
      <string>/Users/myusername</string>
      <key>choiceIdentifier</key>
      <string>default</string>
    </dict>
  </array>
</plist>
  1. The curl command can be used to download the pkg installer. Specify the name of the file to which the downloaded package should be written with the -o option. AWSCLIV2.pkg in the current folder is where the file is stored.
$ curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"  
  1. The following options should be selected during the macOS installer:
  2. Using the -pkg parameter, specify the package name for installation.
  3. Set the -target parameter to CurrentUserHomeDirectory to install only to a current user.
  4. Use the -applyChoiceChangesXML parameter to specify the path (relative to the current folder) and name of the XML file you created.
  5. Install the AWS CLI by copying the file to the folder /Users/myusername/aws-cli.
$ installer -pkg AWSCLIV2.pkg \             -target CurrentUserHomeDirectory \             -applyChoiceChangesXML choices.xml
$ installer -pkg AWSCLIV2.pkg \
            -target CurrentUserHomeDirectory \
            -applyChoiceChangesXML choices.xml
  1. The installer in this mode does not attempt to add symlinks to the aws_completer and aws-completer programs because your $PATH typically does not permit writing to folders. You need to manually create symlinks after the installation finishes in order for the AWS CLI to run properly. The following command can be run without sudo if you’ve included a folder in your $PATH and specified the folder as the target’s path. When you are not in possession of a writable folder in $PATH, you must use sudo to grant written permissions to the specified target folder. Symlinks are created as symlinks in /usr/local/bin.
$ sudo ln -s /folder/installed/aws-cli/aws /usr/local/bin/aws $ sudo ln -s /folder/installed/aws-cli/aws_completer /usr/local/bin/aws_completer
$ sudo ln -s /folder/installed/aws-cli/aws /usr/local/bin/aws
$ sudo ln -s /folder/installed/aws-cli/aws_completer /usr/local/bin/aws_completer
  1. /var/log/install.log is the place where debug logs are stored after the installation has been completed.
  2. Use the following commands to verify that the shell can find and run the aws command in $PATH.
$ which aws
/usr/local/bin/aws 
$ aws --version
aws-cli/2.4.5 Python/3.8.8 Darwin/18.7.0 botocore/2.4.5

Adding the AWS CLI to your path may be the solution if the aws command cannot be found. Please restart your terminal if necessary.

Windows

  1. Installation requirements
    1. AWS CLI is supported on 64-bit versions of Windows supported by Microsoft.
    2. Installing the software requires administrator rights.
  2. Install or update the AWS CLI

You can update your AWS CLI installation on Windows by downloading a new installer each time you update, overwriting the previous version. Updates are released frequently. View the AWS CLI changelog on GitHub to learn when the latest version was released.

  1. To install AWS CLI on Windows (64-bit), download and run the following files:
 https://awscli.amazonaws.com/AWSCLIV2.msi
  1. Alternatively, you can run the MSI installer using the msiexec command.
 C:\> msiexec.exe /i https://awscli.amazonaws.com/AWSCLIV2.msi

 The msiexec manual offers details on the parameters it can be used with

  • on the Microsoft Docs website.
  • In order to check the installation, use the cmd command at the command prompt. You can open the Start menu and find cmd by searching for it.
C:\> aws --version aws-cli/2.4.5 Python/3.8.8 Windows/10 exe/AMD64 prompt/off

To refresh the path, do the following: Close and reopen your command prompt window, or Add the Amazon Web Services CLI to your computer’s path.

Abhay Singh

I'm Abhay Singh, an Architect with 9 Years of It experience. AWS Certified Solutions Architect.

More Reading

Post navigation

Leave a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *