How to install and configure the AWS client

In this article we will see how we can install the AWS client using two simple shell scripts. The scripts are: conf_vars.sh

  • will hold your AWS account credentials and your region data.
installAWSClient.sh
  • will download, install and configure your AWS client.
Lets see the content of the scripts: conf_vars.sh
#! /bin/sh
aws_access_key_id="aws_access_key_id"
aws_secret_access_key="aws_secret_access_key"
region=us-east-1
  • edit the file and add your credentials and region.
installAWSClient.sh
#! /bin/sh


sudo sh -c '(
. ./conf_vars.sh
echo Install and configure AWS Client
cd /tmp
yum install -y unzip
curl https://s3.amazonaws.com/aws-cli/awscli-bundle.zip -o awscli-bundle.zip
unzip -o awscli-bundle.zip
./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
mkdir -p ~/.aws
cat  ~/.aws/credentials <<EOF
[default]
aws_access_key_id = $aws_access_key_id
aws_secret_access_key = $aws_secret_access_key
EOF
cat  ~/.aws/config <<EOF
[default]
output = table
region = $region
EOF
chmod 600 ~/.aws/*
cp -R ~/.aws ~root
chown -R root.root ~root/.aws
chmod 600 ~root/.aws/*
)'
echo AWS Client installed
Create this two shell scripts on your Linux box and make them executable.
chamod 740 "file name"
Lets demo the script execution.
  • it is quite straight foreword.
[root@aodba]# ./installAWSClient.sh
Install and configure AWS CLI
Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main/latest | 2.1 kB 00:00
amzn-updates/latest | 2.3 kB 00:00
Resolving Dependencies
-- Running transaction check
--- Package unzip.x86_64 0:6.0-2.9.amzn1 will be installed
-- Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================
 Package Arch Version Repository Size
====================================================================================================================
Installing:=
 unzip x86_64 6.0-2.9.amzn1 amzn-main 196 k

Transaction Summary
====================================================================================================================
Install 1 Package

Total download size: 196 k
Installed size: 338 k
Downloading packages:
unzip-6.0-2.9.amzn1.x86_64.rpm | 196 kB 00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
 Installing : unzip-6.0-2.9.amzn1.x86_64 1/1
 Verifying : unzip-6.0-2.9.amzn1.x86_64 1/1

Installed:
 unzip.x86_64 0:6.0-2.9.amzn1

Complete!
 % Total % Received % Xferd Average Speed Time Time Time Current
 Dload Upload Total Spent Left Speed
100 6469k 100 6469k 0 0 10.8M 0 --:--:-- --:--:-- --:--:-- 10.8M
Archive: awscli-bundle.zip
 inflating: awscli-bundle/install
 inflating: awscli-bundle/packages/jmespath-0.9.0.tar.gz
 inflating: awscli-bundle/packages/rsa-3.3.tar.gz
 inflating: awscli-bundle/packages/simplejson-3.3.0.tar.gz
 inflating: awscli-bundle/packages/python-dateutil-2.4.2.tar.gz
 inflating: awscli-bundle/packages/ordereddict-1.1.tar.gz
 inflating: awscli-bundle/packages/botocore-1.3.20.tar.gz
 inflating: awscli-bundle/packages/colorama-0.3.3.tar.gz
 inflating: awscli-bundle/packages/docutils-0.12.tar.gz
 inflating: awscli-bundle/packages/argparse-1.2.1.tar.gz
 inflating: awscli-bundle/packages/awscli-1.9.20.tar.gz
 inflating: awscli-bundle/packages/pyasn1-0.1.9.tar.gz
 inflating: awscli-bundle/packages/virtualenv-13.0.3.tar.gz
 inflating: awscli-bundle/packages/six-1.10.0.tar.gz
Running cmd: /usr/bin/python virtualenv.py --python /usr/bin/python /usr/local/aws
Running cmd: /usr/local/aws/bin/pip install --no-index --find-links file:///tmp/awscli-bundle/packages awscli-1.9.20.tar.gz
Symlink already exists: /usr/local/bin/aws
Removing symlink.
You can now run: /usr/local/bin/aws --version
AWS CLI installed
Test your AWS client installation.
[root@aodba]# aws --version

aws-cli/1.9.20 Python/2.7.10 Linux/4.1.10-17.31.amzn1.x86_64 botocore/1.3.20
or 
[root@aodba]# aws ec2 describe-regions
----------------------------------------------------------
|                     DescribeRegions                    |
+--------------------------------------------------------+
||                        Regions                       ||
|+-----------------------------------+------------------+|
||             Endpoint              |   RegionName     ||
|+-----------------------------------+------------------+|
||  ec2.eu-west-1.amazonaws.com      |  eu-west-1       ||
||  ec2.ap-southeast-1.amazonaws.com |  ap-southeast-1  ||
||  ec2.ap-southeast-2.amazonaws.com |  ap-southeast-2  ||
||  ec2.eu-central-1.amazonaws.com   |  eu-central-1    ||
||  ec2.ap-northeast-2.amazonaws.com |  ap-northeast-2  ||
||  ec2.ap-northeast-1.amazonaws.com |  ap-northeast-1  ||
||  ec2.us-east-1.amazonaws.com      |  us-east-1       ||
||  ec2.sa-east-1.amazonaws.com      |  sa-east-1       ||
||  ec2.us-west-1.amazonaws.com      |  us-west-1       ||
||  ec2.us-west-2.amazonaws.com      |  us-west-2       ||
|+-----------------------------------+------------------+|
Great your AWS client is ready to be used.

Wanna see the Video version as well ? See Here!