How Do You Install and Configure the AWS CLI on a Linux Server (without the pip Command)?

Problem scenario
Using different package managers can lead to dependencies being met while systems administrators will encounter error messages that detect, find or determine something to the contrary (e.g., false unmet dependency errors or conditions).  Some enterprise policies disallow the pip command.  How do you set up the AWS CLI on a Linux server without the pip command?

Solution (Part 1 and Part 2)
Prerequisites
i.  You must have Python installed.  Run this command:  python --version
Make a mental note of the version if it is installed. You may want to try this too (if the command did not work): python3 --version

ii.  This only applies if you are using CentOS/RHEL/Fedora.  (Skip this prerequisite (ii and all of its sub-steps) if you are using a different distribution of Linux):
ii.a.  Do this if you don't have Python:  sudo yum -y install python3
ii.b.  You need pip or pip3 to be installed.  If you need help installing pip, see this posting.
ii.c.  Run this command:  sudo pip3 install colorama rsa s3transfer ruamel.yaml botocore  # Use "pip3" instead of "pip" if you have "pip3". You may want to try sudo /usr/local/bin/pip if pip3 cannot be found.

iii.  If Python is not already installed, run one of the following if you have Debian or Ubuntu Linux:
sudo apt -y install python3
or
sudo apt -y install python

Procedures
Part 1:  Install AWS CLI
Step #1:  If the AWS CLI has already been installed, skip to step #5.  Otherwise using a web browser, go to the GitHub site to retrieve the .tar.gz file with the installation media. You may want to use curl -L <URL found above> > /tmp/nameoffile

Step #2:  Click on the desired version (e.g., 1.18).

Step #3:  Right click the hyperlink for "Source code (tar.gz)" and copy that hyperlink.

Step #4.a:  If you are running Debian or Ubuntu Linux, do this step, otherwise skip to step 4.b:
If you are running Python version 2.x, run this command:  sudo apt-get -y install python-setuptools
If you are running Python version 3.x, run this command:  sudo apt-get install python3-setuptools

Step #4.b:  Run these commands:
curl -L https://.../1.16.foobar.tar.gz > /tmp/1.16.foobar.tar.gz   #where https://.../1.11.foobar.tar.gz  is the hyperlink copied in the step above.
sudo mv /tmp/1.16.foobar.tar.gz /bin
cd /bin
sudo tar -zxvf 1.16.foobar.tar.gz 
 # where foobar.tar.gz is the name of file downloaded from the above curl
cd aws-cli.version  #where aws-cli.version is the name of the directory created in the above step
sudo python3 setup.py build   #This command should be with "python" instead of "python3" if you have Python 2.x only.
# *** (See below.)
sudo python3 setup.py install  #This command should be with "python" instead of "python3" if you have Python 2.x only.
Run this: sudo ln -s /usr/local/bin/aws /bin/aws
sudo aws --version or aws --version  # The response should indicate a version.  If the command was not found, aws cli was not installed.

Part 2:  Configure AWS CLI
If AWS CLI is already installed, start with step #5.

Step #5: You must have your default region name, AWS Access Key ID, and AWS Secret Access Key available.  If you have them, skip the next steps and start working at Step #9.  To retrieve the region name, log into the AWS console from a web browser.  By default when you log in, the URL should have what you need.  Find the portion of the URL that is to the right of the "=" sign.  For example, "us-east-1" is to the right of the "=" sign: https://console.aws.amazon.com/console/home?region=us-east-1

Step #6: To find the AWS Access Key ID and AWS Secret Access Key, in the AWS console, click on your name in the upper right hand corner.  Then click on "My Security Credentials."

Step #7:  Click "Create New Access Key"

Step #8:  Click "Show Access Key."  Keep these values handy for the next step.

Step #9:  Log into the Linux server with AWS CLI.  Type this command followed by "Enter":  aws configure

Respond to the first three prompts with something; the last of the four prompts can be blank and you can just press "enter."

AWS Access Key ID [None]: 
AWS Secret Access Key [None]: 
Default region name [None]: 
Default output format [None]:

Step #10:  To test, try this command followed by "Enter": aws ec2 describe-instances
This will test that you have connectivity to your AWS account, the AWS Access Key ID has permissions to list the EC2 (virtual) servers, and the AWS Secret Access Key was valid.

Finally, if you need an American or offshore AWS consultant, please submit your request to sales [at] americandevops [dot] com and reference "continualintegration.com" for a discount.  They can handle on-site needs for large enterprises or small freelance projects done remotely.

*** If commands above or below the three asterisks "***" throw an error about the version of setuptools being too low, try the command again.  It may work a second time.  This is only advisable if you are setting up a proof-of-concept or configuring an environment without sensitive data.  For production or hardened environments, you may want to investigate as normal.  If you need assistance installing the latest version of setuptools (and it may not be necessary, repeating the command may work as a kludge), see this posting.  You may need to follow that posting's directions, then run the commands to build and install setup.py for setuptools in a repetitive way.  We only recommend repeating the commands that failed the first time to make it work if you are not using sensitive data.  There may be a more serious issue at hand.

In Case You Want Something Different
If you are using Debian/Ubuntu Linux and can install pip (or have pip installed), you can install the AWS CLI with this alternative directions.

Leave a comment

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