How to Install and Configure AWS CLI

How to Install and Configure AWS CLI

AWS Command Line Interface (AWS CLI) is a fantastic tool that will let you interact with AWS services using commands in your Command line tool. These AWS CLI Commands can be executed from any of the Command-Line tools in your operating system If you have installed the AWS CLI SDK installed properly on it. In this article, we will discuss how to install and configure AWS CLI on different platforms. AWS released two different versions of the AWS CLI till now. In this article, we will discuss How to install and Configure AWS CLI Version 2.

Installing AWS CLI Version 2 with Docker.

As we know, Docker is a fantastic tool that will create a lightweight virtual environment that is totally platform-independent. So, to Install and use AWS CLI, Docker will help us with the latest AWS CLI without even installing it on the host operating system.

Prerequisites

  • All you need is Docker installed on your host machine. There is nothing else required if you are using Docker to install AWS CLI.

Installation

As we already mentioned, you don’t have to install any software or application to run AWS CLI with docker. But you need to install the Official Docker Image for AWS CLI. For the same follow the below steps.

  • Pull the Docker Image by using the following command
$ docker pull amazon/aws-cli
  • Run the Docker run Command with the AWS CLI command you need to execute. Example.
$ docker run --rm -it amazon/aws-cli s3 ls

That’s all, the above command will give you the list of objects available in the AWS account.

However, Running AWS CLI on Docker container has some solvable issues, which are sharing files, Credentials, Environment Variables from the Host to Container. For the same, you should use the volume sharing arguments with the docker command. For example,

$ docker run --rm -it -v ~/.aws:/root/.aws amazon/aws-cli command

So, here, the credentials and other information saved inside ~/.aws folder will be stored inside /root/.aws in the Docker Container.

Installing AWS CLI Version 2 on Linux.

Before Installing the AWS CLI on Linux, Let discuss the prerequisites.

Prerequisites

  1. Uninstall the AWS CLI Version 1 If you have installed it already.
  2. Install unzip tool if you don’t have that in your operating system by default
  3. Install Libraries like glibs, groff, and less
  4. OS Architecture Linux x86 (64-bit) or Linux ARM

Installation

On Linux x86 (64-bit)

To install AWS CLI on Linux x86 (64-bit), use the following commands.

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

on Linux ARM

To install AWS CLI on Linux ARM, use the following commands.

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

To install the different versions, Visit the AWS CLI Github repository release page to get the desired version of AWS CLI.

Installing AWS CLI Version 2 on macOS.

Before Installing the AWS CLI on macOS, Let discuss the prerequisites.

Prerequisites

  1. 64-bit macOS is required
  2. Xcode or developer tools enabled.

Installation

Installing with user interface

  1. Go to your browser in macOS and enter this link – https://awscli.amazonaws.com/AWSCLIV2.pkg
  2. Double click the downloaded file to launch the installer.
  3. Then, follow the instruction.

Installing with macOS Terminal

To install AWS CLI on the macOS, run the following commands one by one.

$ curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
$ sudo installer -pkg AWSCLIV2.pkg -target /

From the either ways, you can test the installation by running aws --version in the command line. This should return the installed version, If it is installed properly.

Installing AWS CLI Version 2 on Windows.

Before Installing the AWS CLI on Windows, Let discuss the prerequisites.

Prerequisites

  1. 64-bit Windows is required
  2. Windows XP or Later Required
  3. Administrator Access Required

Installation

Installing AWS CLI in windows is very easy. All you need to do is to follow the below steps.

  1. Download the Installer from the amazon website – https://awscli.amazonaws.com/AWSCLIV2.msi
  2. Double click the Installer you downloaded
  3. Follow the instructions.

That’s all the Installation on AWS CLI in the Windows OS. And to confirm the Installation, Just run aws –version in the command prompt and It should return the version number if it is installed properly.

Configuring AWS CLI

Once you install the AWS CLI, You can configure the AWS CLI to point your AWS Account with the credentials and other details where you want to work. For the same, Just enter the aws configure command in the command line and it will ask you the information one by one. Example,

$ aws configure
AWS Access Key ID [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXX
Secret Access Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Default region name [None]: us-east-1
Default output format [None]: json

This will create a AWS configuration file in the user’s home directory. (~/.aws/credentials and ~/.aws/config).

You may wonder What and where to get the Access Key and Secret Key of the AWS Account. To know or generate your AWS Access Key and Secret Key, follow the below instructions.

To get AWS Access key and Secret Key:

  1. Login to AWS Console
  2. Go to IAM services
  3. Select Users in the left Navigation panel
  4. Chose the User you want to give access for
  5. Select Security Credentials Tab
  6. Select Create Access key from Access Key Section
  7. Click Show to reveal the Access Key and Secret Key and save it.

That’s all the Basic configuration of AWS CLI.

Conclusion

In this article, we have discussed How to Install and Configure Amazon AWS CLI on various Operating systems like Windows, macOS, Linux, and Docker. In our upcoming article, we will discuss Important Commands to remember while using AWS CLI and automating AWS Engineering with AWS CLI along with some scripting language. We will discuss the same in our upcoming article. Stay tuned and subscribe DigitalVarys for more articles and study materials on DevOps, Agile, DevSecOps, and App Development.

Leave a Reply