OS X install Amazon AWS command-line interface (CLI) tool

Posted on in Categories , , last updated February 3, 2016

How do I setup and install the official Amazon AWS Command Line Interface (cli) on an Apple Mac OS X system?

The official or universal command line interface for Amazon Web Services recommended tool for the AWS. There are various ways to install the AWS CLI.

Prerequisites

You must have Python installed on the system. The aws cli package works on Python versions:

  • 2.6.5+
  • 2.7.x+
  • 3.3.x+
  • 3.4.x+

Finding out your Python version

Open the Terminal and type the following command:
$ python --version
$ sw_vers

Sample outputs:

Fig.01: OS X Find Out Python Version
Fig.01: OS X Find Out Python Version

Method #1: Install the aws-cli using brew

Type the following command:
$ brew install awscli
Add the following to ~/.bashrc to enable bash completion for aws command:

 echo 'complete -C aws_completer aws' >> ~/.bashrc

Add the following to ~/.zshrc to enable zsh completion:

 echo 'source /usr/local/share/zsh/site-functions/_aws' >> ~/.zshrc

Method #2: Install the aws-cli using the official Amazon installer

Type the following command:
$ cd /tmp
$ curl -o awscli.zip https://s3.amazonaws.com/aws-cli/awscli-bundle.zip

  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 6501k  100 6501k    0     0   399k      0  0:00:16  0:00:16 --:--:--  542k

Unzip the awscli.zip file:
$ unzip awscli.zip
Sample outputs:

Archive:  awscli.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/colorama-0.3.3.tar.gz  
  inflating: awscli-bundle/packages/docutils-0.12.tar.gz  
  inflating: awscli-bundle/packages/botocore-1.3.23.tar.gz  
  inflating: awscli-bundle/packages/argparse-1.2.1.tar.gz  
  inflating: awscli-bundle/packages/awscli-1.10.1.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

Install it:
$ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws
Sample outputs:

Running cmd: /usr/local/opt/python/bin/python2.7 virtualenv.py --python /usr/local/opt/python/bin/python2.7 /usr/local/aws
Running cmd: /usr/local/aws/bin/pip install --no-index --find-links file:///private/tmp/awscli-bundle/packages awscli-1.10.1.tar.gz
Symlink already exists: /usr/local/bin/aws
Removing symlink.
You can now run: /usr/local/bin/aws --version

How do I use the aws-cli?

You must have an AWS account. Visit http://aws.amazon.com/.

Create the AWS access key ID and secret access key

  1. Visit the IAM console
  2. Select your IAM user name.
  3. Select the Security Credentials tab and then Create Access Key.

Sample outputs:

Fig.02:  Get your access key ID and secret access key
Fig.02: Get your access key ID and secret access key

To see your access key, choose Show User Security Credentials.
Fig.03: Choose Download Credentials, and store the keys in a secure location
Fig.03: Choose Download Credentials, and store the keys in a secure location

Configure the aws-cli

Type the following command and when prompted enter the AWS Access Key ID and AWS Secret Access Key:
$ aws configure
Sample outputs:

Fig.04: aws configure in action
Fig.04: aws configure in action

Now you can use the aws command to control your cloud hosted by the Amazon AWS. The syntax is:
$ aws command
$ aws help
$ aws ec2 help
## examples ##
$ aws ec2 describe-instances --output table
$ aws --region=us-east-1 acm list-certificates
$ aws --region=us-east-1 acm list-certificates --certificate-statuses ISSUED

References

See Using the AWS Command Line Interface for more information.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin and a trainer for the Linux operating system/Unix shell scripting. He has worked with global clients and in various industries, including IT, education, defense and space research, and the nonprofit sector. Follow him on Twitter, Facebook, Google+.

3 comment

  1. So I have the AWS CLI installed on my Mac running el Capitan. I am pleased with my initial testing of entering commands. I really need to be able to run the commands as a shell script so that I can run them unattended. But I get errors each time I attempt to run my command line as a shell script.

    Can anyone offer advice on this, please?
    Thank you very much for your time and assistance.

Leave a Comment