Skip to main content
Home
badllama.com
  • Search
  • Log In

How to install the AWS CLI on Windows, OSX, and Linux

cpeters's picture

Fri, 08/05/2016 - 13:13 by cpeters

If you work with the AWS CLI and it's cousins, you notice quickly that there are different versions and functionality depending on which version of python you use to install them. Therefore, I recommend setting up a virtual environment for each version of python, so you can always be working with the most functional packages and not have to create confusion in your root environment.

OSX

Step 1: Install tooling

  1. brew: Covered in this link
  2. pip:
    sudo easy_install pip
  3. virtualenv:
    sudo pip install virtualenv
  4. Python3:
    brew install python3

Step 2: Setup a virtual environment for your python versions

mkdir ~/Projects
cd ~/Projects
pyvenv 35-python
virtualenv --system-site-packages 27-python

Step 3: Test your new virtual environments

cd ~/Projects/35-python
source bin/activate
(35-python) [HOSTNAME]$ python --version
(35-python) [HOSTNAME]$ deactivate
cd ~/Projects/27-python
source bin/activate
(27-python) [HOSTNAME]$ python --version
(27-python) [HOSTNAME]$ deactivate

Step 4: Install your AWS toolkits into your virtual environments

cd ~/Projects/35-python
source bin/activate
easy_install pip
pip install --upgrade pip
pip install awscli
deactivate

cd ~/Projects/27-python
source bin/activate
easy_install pip
pip install --upgrade pip
pip install awscli
deactivate

AWS Linux

yum install gcc openssl-devel.x86_64 -y
          rinse / repeat instructions from OSX steps 2, 3 & 4

Windows

Important Notes

  1. ANSIBLE DOESN'T RUN FROM PIP IN WINDOWS! There are lots of tools that will work, but Ansible isn't one of them.
  2. the AWS CLI requires Powershell 5. To check your version:
  3. [User@frankenamr:SecureCloud-27]$ $psversiontable
    
    Name                           Value
    ----                           -----
    PSVersion                      5.0.10586.117
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    BuildVersion                   10.0.10586.117
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
        
  4. If you don't have Powershell 5, you can get it here

Instructions

  1. download and install Python 2.7
  2. download and install Python 3.5
  3. add c:\python27 and c:\python27\Scripts to your PATH
  4. Install virtualenv:
        pip install pip --upgrade (ignore errors)
        pip install virtualenv
        pip install virtualenvwrapper-powershell (optional)
        
  5. Create your Python-27 environment:
        mkdir ~\Documents\Projects
        cd ~\Documents\Projects
        virtualenv 27-Python
        
  6. Create your Python-35 environment:
        cd ~\Documents\Projects
        c:\Python35\python.exe -m venv 35-Python
        
  7. Test your environments as outlined above in step 3, using the following command to activate your environments:
    [User@m-20eg-r90ha96z:35-Python]$ .\Scripts\activate

Test an ansible deployment against AWS

  1. Install packages using pip
  2. Python 2.7
    pip install ansible --user python
    pip install boto
    
  3. Python 3.x
    pip install ansible
    pip install boto
    
  4. Create your inventory
    vim inventory.ini
    Insert the following:
    [localhost]
    localhost
    
    write and quit
  5. Create your credentials
    vim ~/.boto
    Insert the following text:
    [Credentials]
    aws_access_key_id  = ACCESS_KEY
    aws_secret_access_key = SECRET_KEY
    Write and quit
  6. Create a simple playbook
    vim hello-world.yml
    insert the following text:
    - name: Create a sandbox instance
      hosts: localhost
      gather_facts: False
      vars:
        key_pair: [KEY-NAME]
        instance_type: t2.micro
        image: ami-6869aa05
        region: us-east-1
      tasks:
        - name: Launch instance
          ec2:
             key_name: "{{ key_pair }}"
             instance_type: "{{ instance_type }}"
             image: "{{ image }}"
             wait: true
             region: "{{ region }}"
             vpc_subnet_id: subnet-5e7f9e17
             assign_public_ip: yes
          register: ec2
        - name: Add new instance to host group
          add_host: hostname={{ item.public_ip }} groupname=launched
          with_items: ec2.instances
        - name: Wait for SSH to come up
          wait_for: host={{ item.public_dns_name }} port=22 delay=60 timeout=320 state=started
          with_items: ec2.instances
    
    Write and quit
  7. Run your playbook
    ansible-playbook hello-world.yml
Tags: 
osx
Ansible
AWS
virtualenv
pyvenv
python
Windows
Powered by Backdrop CMS