AWS CLI Tools 1

Introduction to AWS Command Line Interface Tools-1

Installation

In this series of short tutorials, I walk you through the  journey of Installing AWS CLI Tool and using the commands to manage various AWS  Services. This introductory part of the tutorial is a walk through installing AWS CLI Tool on MacOS.

There are 3 methods I am familiar with to install AWS CLI on a MacOS.

1. Install Python, pip and AWS CLI via pip installer.

Download and install the latest version of Python and pip to use them to install the AWS CLI. Why? AWS CLI uses Python Library and pip is a Python package management system used to install and manage software packages written in Python.

Difference between pip and pip3?

  1. If pip is already on your system, follow the installation instructions below. Run pip --version on your terminal to confirm the version of Python and pip. MacOsX comes pre-installed with Python 2.7.
  2. Download and install Python 3.6 from the downloads page of Python.org.
  3. Install pip with the script provided by the Python Packaging Authority.
    $ curl -O https://bootstrap.pypa.io/get-pip.py
    $ python3 get-pip.py --user
  4. Use pip to install AWS CLI
    $ pip3 install awscli --upgrade --user
  5. Verify that the AWS CLI installation is done correctly.
    $ aws --version
    AWS CLI 1.11.84 (Python 3.6.1)
  6. If the executable is not found, add it to your command line path.

To upgrade to the latest version, re-run the installation command.

$ pip3 install awscli --upgrade --user

2. Download and install via the “awscli-bundle.zip”

$ curl "https://s3.amazonaws.com/aws-cli/awscli-bundle.zip" -o "awscli-bundle.zip"
$ unzip awscli-bundle.zip
$ sudo ./awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws

The third step above will set the the path correctly.

3. Another method is via Homebrew. This perhaps is the easiest method as it installs directly to the brew repository.

brew install awscli

My brew installation looks something like this (I am using zsh $SHELL):

==> Downloading https://homebrew.bintray.com/bottles/awscli-1.11.136.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring awscli-1.11.136.sierra.bottle.tar.gz
==> Caveats
The "examples" directory has been installed to:
  /usr/local/share/awscli/examples

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d

zsh completions have been installed to:
  /usr/local/share/zsh/site-functions
==> Summary
🍺  /usr/local/Cellar/awscli/1.11.136: 4,091 files, 35.3MB

To confirm location of the install, you can run the command below confirming mine is in the following directory /bin/aws

 ~/ [master*] which aws
/usr/local/bin/aws

To download the development version of awscli, you can use the --HEAD flag.

brew install awscli --HEAD

Configuring AWS CLI

We can configure the account using the aws configure command in the terminal.

While configuring, it will ask you for the several information like AWS Access Key ID, AWS Secret Access Key, Default region name, Default output format. You need to provide that information. In my case below is the Access Key and Secret Access Key which is generated while creating a User in the AWS Admin Dashboard.

AWS Access Key ID [None]:AKIAI4QT3SHFXWALVL2A
AWS Secret Access Key[None]:CntSGhTRiDyYp6cOV7hhU2n0qFhUO25phWptEi

**Make sure to take a note of them while they are generated.

 ~/ [master*] aws configure
AWS Access Key ID [None]:AKIAI4QT3SHFXWALVL2A
AWS Secret Access Key [None]:CntSGhTRiDyYp6cOV7hhU2n0qFhUO25phWptEi
Default region name [None]: ap-south-1
Default output format [None]:

Once configuration completes, it will create .aws folder in user’s home directory with 2 files. Below is the content of .aws directory.

 ~/.aws/ [master*] tree
.
├── config
└── credentials

The Config File has the default region name set at the time of running the aws configure

 ~/.aws/ [master*] cat config
[default]
region = ap-south-1

This has the keys of the user configured.

 ~/.aws/ [master*] cat credentials
[default]
aws_access_key_id = AKIAI4QT3SHFXWALVL2A
aws_secret_access_key = CntSGhTRiDyYp6cOV7hhU2n0qFhUO25phWptEi

Now that we have installed awscli and configured the user, we can try running a command to check a list of aws regions.

 ~/ [master*] aws ec2 describe-regions
{
    "Regions": [
        {
            "Endpoint": "ec2.ap-south-1.amazonaws.com", 
            "RegionName": "ap-south-1"
        }, 
        {
            "Endpoint": "ec2.eu-west-2.amazonaws.com", 
            "RegionName": "eu-west-2"
        }, 
        {
            "Endpoint": "ec2.eu-west-1.amazonaws.com", 
            "RegionName": "eu-west-1"
        }, 
        {
            "Endpoint": "ec2.ap-northeast-2.amazonaws.com", 
            "RegionName": "ap-northeast-2"
        }, 
        {
            "Endpoint": "ec2.ap-northeast-1.amazonaws.com", 
            "RegionName": "ap-northeast-1"
        }, 
        {
            "Endpoint": "ec2.sa-east-1.amazonaws.com", 
            "RegionName": "sa-east-1"
        }, 
        {
            "Endpoint": "ec2.ca-central-1.amazonaws.com", 
            "RegionName": "ca-central-1"
        }, 
        {
            "Endpoint": "ec2.ap-southeast-1.amazonaws.com", 
            "RegionName": "ap-southeast-1"
        }, 
        {
            "Endpoint": "ec2.ap-southeast-2.amazonaws.com", 
            "RegionName": "ap-southeast-2"
        }, 
        {
            "Endpoint": "ec2.eu-central-1.amazonaws.com", 
            "RegionName": "eu-central-1"
        }, 
        {
            "Endpoint": "ec2.us-east-1.amazonaws.com", 
            "RegionName": "us-east-1"
        }, 
        {
            "Endpoint": "ec2.us-east-2.amazonaws.com", 
            "RegionName": "us-east-2"
        }, 
        {
            "Endpoint": "ec2.us-west-1.amazonaws.com", 
            "RegionName": "us-west-1"
        }, 
        {
            "Endpoint": "ec2.us-west-2.amazonaws.com", 
            "RegionName": "us-west-2"
        }
    ]
}

If you’ve reached this part of the mini-series, you are all set to get down and dirty with awscli Tool. Thank you for taking out the time to read, hope this was helpful.

Someone once told me a long time ago that knowledge is power, but one needs passion, curiosity and hunger, thus is acquired with patience, and builds into wisdom that lingers on. The first step is the beginning of a journey. As we go along the way we assimilate and learn from each other, share our knowledge and experiences with the rest of the world. I am glad to share my experiences I came across preparing for my AWS Solutions Architect Certification.

If you like this tut or have any feedback or comments, please engage us below. Stay tuned for the next part of the mini-tuts.

Jesmin Ningthoujam

Passionately curious, 14+ years in the IT Enterprise Network Delivery Domain. Passionate about Open Source, disruptive & emerging technologies. Project Manager CI/CD, Cloud Deployment & Automation. Loves music, a seasonal Artist & Graphic Designer.