The easiest way to install the AWS CLI is using pip, it is a package manager for Python that provides an easy way to install, upgrade, and remove Python packages and their dependencies.
Install Python pip
CentOS :
sudo yum update -y
sudo yum install -y python-pip
Ubuntu :
sudo apt-get update -y
sudo apt-get install -y python-pip
Install AWS CLI using pip
pip install awscli --upgrade --user
–upgrade option tells pip to upgrade any requirements that are already installed.
–user option tells pip to install the program to a subdirectory of your user directory to avoid modifying libraries used by your operating system.
Add the executable path to your PATH variable: ~/.local/bin
export PATH=$PATH:~/.local/bin
Load the profile into your current session
source ~/.bash_profile
Verify that the AWS CLI installed correctly by running aws --version
.
aws --version aws-cli/1.16.19 Python/2.7.5 Linux/3.10.0-862.11.6.el7.x86_64 botocore/1.12.9
Configure AWS CLI
To access aws services using cli, we need to provide the access key and secret key along with a default region. This can be done using a subcommand provided by aws cli.
$ aws configure
AWS Access Key ID [None]: XXXXXXXXXXXXXXXXXXXX
AWS Secret Access Key [None]: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Default region name [None]: us-east-1
Default output format [None]: json
I have used us-east-1 as default region and default output format is JSON. We can format the output as text and table formats as well.
aws configure command creates two configuration files located under .aws in user home directory.
ls ~/.aws/ config credentials
cat config
[default]
output = json
region = us-east-1
cat credentials
[default]
aws_access_key_id = XXXXXXXXXXXXXXXXXXXX
aws_secret_access_key = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Verify if AWS CLI configuration
Describe your regions
aws ec2 describe-regions { "Regions": [ { "Endpoint": "ec2.ap-south-1.amazonaws.com", "RegionName": "ap-south-1" }, { "Endpoint": "ec2.eu-west-3.amazonaws.com", "RegionName": "eu-west-3" }, { "Endpoint": "ec2.eu-west-2.amazonaws.com", "RegionName": "eu-west-2" }, ..... ..... { "Endpoint": "ec2.us-west-2.amazonaws.com", "RegionName": "us-west-2" } ] }