Mac OS X 開発環境構築手順:AWS CLI(AWS Command Line Interface)&jq(軽量JSONパーサーツール)

専らこのツールはAWS EC2インスタンスの環境上で導入して利用しているのですが、MBA上でも普通に使えたほうが良いなと思い導入。導入手順は全く変わらない為、作業記録的なものとして残しておきます。

  • Pythonはインストール済みである所から始めました。
$ python --version
Python 2.7.1
  • まず最初に『sudo easy_install pip』でpipをインストール。
$ sudo easy_install pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Best match: pip 1.3.1
Downloading https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz#md5=cbb27a191cebc58997c4da8513863153
Processing pip-1.3.1.tar.gz
Running pip-1.3.1/setup.py -q bdist_egg --dist-dir /tmp/easy_install-y3L5h5/pip-1.3.1/egg-dist-tmp-LZwfPU
warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.txt' found under directory 'docs/_build'
no previously-included directories found matching 'docs/_build/_sources'
Adding pip 1.3.1 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip-2.7 script to /usr/local/bin

Installed /Library/Python/2.7/site-packages/pip-1.3.1-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
$
  • 次いで『sudo pip install awscliaws-cliをインストール。途中warning出てるけど問題無い...のかな?
$ sudo pip install awscli
Downloading/unpacking awscli
  Downloading awscli-0.12.0.tar.gz
  Running setup.py egg_info for package awscli
    
Downloading/unpacking botocore>=0.12.0,<0.13.0 (from awscli)
  Downloading botocore-0.12.0.tar.gz (633kB): 633kB downloaded
  Running setup.py egg_info for package botocore
    
Downloading/unpacking bcdoc>=0.4.2,<0.5.0 (from awscli)
  Downloading bcdoc-0.4.3.tar.gz
  Running setup.py egg_info for package bcdoc
    
Downloading/unpacking six>=1.1.0 (from awscli)
  Downloading six-1.3.0.tar.gz
  Running setup.py egg_info for package six
    
Downloading/unpacking colorama==0.2.5 (from awscli)
  Downloading colorama-0.2.5.tar.gz
  Running setup.py egg_info for package colorama
    
Downloading/unpacking argparse>=1.1 (from awscli)
  Downloading argparse-1.2.1.tar.gz (69kB): 69kB downloaded
  Running setup.py egg_info for package argparse
    
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.pyo' found anywhere in distribution
    warning: no previously-included files matching '*.orig' found anywhere in distribution
    warning: no previously-included files matching '*.rej' found anywhere in distribution
    no previously-included directories found matching 'doc/_build'
    no previously-included directories found matching 'env24'
    no previously-included directories found matching 'env25'
    no previously-included directories found matching 'env26'
    no previously-included directories found matching 'env27'
Downloading/unpacking docutils>=0.10 (from awscli)
  Downloading docutils-0.10.tar.gz (1.6MB): 1.6MB downloaded
  Running setup.py egg_info for package docutils
    
    warning: no files found matching 'MANIFEST'
    warning: no files found matching '*' under directory 'extras'
    warning: no previously-included files matching '.cvsignore' found under directory '*'
    warning: no previously-included files matching '*.pyc' found under directory '*'
    warning: no previously-included files matching '*~' found under directory '*'
    warning: no previously-included files matching '.DS_Store' found under directory '*'
Downloading/unpacking requests==1.2.0 (from botocore>=0.12.0,<0.13.0->awscli)
  Downloading requests-1.2.0.tar.gz (341kB): 341kB downloaded
  Running setup.py egg_info for package requests
    
Downloading/unpacking jmespath==0.0.2 (from botocore>=0.12.0,<0.13.0->awscli)
  Downloading jmespath-0.0.2.tar.gz
  Running setup.py egg_info for package jmespath
    
Downloading/unpacking python-dateutil>=2.1 (from botocore>=0.12.0,<0.13.0->awscli)
  Downloading python-dateutil-2.1.tar.gz (152kB): 152kB downloaded
  Running setup.py egg_info for package python-dateutil
    
Downloading/unpacking ply==3.4 (from jmespath==0.0.2->botocore>=0.12.0,<0.13.0->awscli)
  Downloading ply-3.4.tar.gz (138kB): 138kB downloaded
  Running setup.py egg_info for package ply
    
Installing collected packages: awscli, botocore, bcdoc, six, colorama, argparse, docutils, requests, jmespath, python-dateutil, ply
  Running setup.py install for awscli
    changing mode of build/scripts-2.7/aws from 644 to 755
    changing mode of build/scripts-2.7/aws.cmd from 644 to 755
    changing mode of build/scripts-2.7/aws_completer from 644 to 755
    changing mode of build/scripts-2.7/aws_zsh_completer.sh from 644 to 755
    
    changing mode of /usr/local/bin/aws to 755
    changing mode of /usr/local/bin/aws.cmd to 755
    changing mode of /usr/local/bin/aws_completer to 755
    changing mode of /usr/local/bin/aws_zsh_completer.sh to 755
  Running setup.py install for botocore
    
  Running setup.py install for bcdoc
    
  Running setup.py install for six
    
  Running setup.py install for colorama
    
  Running setup.py install for argparse
    
    warning: no previously-included files matching '*.pyc' found anywhere in distribution
    warning: no previously-included files matching '*.pyo' found anywhere in distribution
    warning: no previously-included files matching '*.orig' found anywhere in distribution
    warning: no previously-included files matching '*.rej' found anywhere in distribution
    no previously-included directories found matching 'doc/_build'
    no previously-included directories found matching 'env24'
    no previously-included directories found matching 'env25'
    no previously-included directories found matching 'env26'
    no previously-included directories found matching 'env27'
  Running setup.py install for docutils
    changing mode of build/scripts-2.7/rst2html.py from 644 to 755
    changing mode of build/scripts-2.7/rst2s5.py from 644 to 755
    changing mode of build/scripts-2.7/rst2latex.py from 644 to 755
    changing mode of build/scripts-2.7/rst2xetex.py from 644 to 755
    changing mode of build/scripts-2.7/rst2man.py from 644 to 755
    changing mode of build/scripts-2.7/rst2xml.py from 644 to 755
    changing mode of build/scripts-2.7/rst2pseudoxml.py from 644 to 755
    changing mode of build/scripts-2.7/rstpep2html.py from 644 to 755
    changing mode of build/scripts-2.7/rst2odt.py from 644 to 755
    changing mode of build/scripts-2.7/rst2odt_prepstyles.py from 644 to 755
    
    warning: no files found matching 'MANIFEST'
    warning: no files found matching '*' under directory 'extras'
    warning: no previously-included files matching '.cvsignore' found under directory '*'
    warning: no previously-included files matching '*.pyc' found under directory '*'
    warning: no previously-included files matching '*~' found under directory '*'
    warning: no previously-included files matching '.DS_Store' found under directory '*'
    changing mode of /usr/local/bin/rst2html.py to 755
    changing mode of /usr/local/bin/rst2latex.py to 755
    changing mode of /usr/local/bin/rst2man.py to 755
    changing mode of /usr/local/bin/rst2odt.py to 755
    changing mode of /usr/local/bin/rst2odt_prepstyles.py to 755
    changing mode of /usr/local/bin/rst2pseudoxml.py to 755
    changing mode of /usr/local/bin/rst2s5.py to 755
    changing mode of /usr/local/bin/rst2xetex.py to 755
    changing mode of /usr/local/bin/rst2xml.py to 755
    changing mode of /usr/local/bin/rstpep2html.py to 755
  Running setup.py install for requests
    
  Running setup.py install for jmespath
    
  Found existing installation: python-dateutil 1.5
    Uninstalling python-dateutil:
      Successfully uninstalled python-dateutil
  Running setup.py install for python-dateutil
    
  Running setup.py install for ply
    
Successfully installed awscli botocore bcdoc six colorama argparse docutils requests jmespath python-dateutil ply
Cleaning up...
$ 
  • sudo pip install awscli --upgrade』でアップグレード実施。
$ sudo pip install awscli --upgrade
Requirement already up-to-date: awscli in /Library/Python/2.7/site-packages
Requirement already up-to-date: botocore>=0.12.0,<0.13.0 in /Library/Python/2.7/site-packages (from awscli)
Requirement already up-to-date: bcdoc>=0.4.2,<0.5.0 in /Library/Python/2.7/site-packages (from awscli)
Requirement already up-to-date: six>=1.1.0 in /Library/Python/2.7/site-packages (from awscli)
Requirement already up-to-date: colorama==0.2.5 in /Library/Python/2.7/site-packages (from awscli)
Requirement already up-to-date: argparse>=1.1 in /Library/Python/2.7/site-packages (from awscli)
Requirement already up-to-date: docutils>=0.10 in /Library/Python/2.7/site-packages (from awscli)
Requirement already up-to-date: requests==1.2.0 in /Library/Python/2.7/site-packages (from botocore>=0.12.0,<0.13.0->awscli)
Requirement already up-to-date: jmespath==0.0.2 in /Library/Python/2.7/site-packages (from botocore>=0.12.0,<0.13.0->awscli)
Requirement already up-to-date: python-dateutil>=2.1 in /Library/Python/2.7/site-packages (from botocore>=0.12.0,<0.13.0->awscli)
Requirement already up-to-date: ply==3.4 in /Library/Python/2.7/site-packages (from jmespath==0.0.2->botocore>=0.12.0,<0.13.0->awscli)
Cleaning up...
$
  • 補完を効かすコマンド設定『complete -C aws_completer aws』も全く同じ形で出来ますね。
$ which aws
/usr/local/bin/aws
$ which aws_completer
/usr/local/bin/aws_completer
$ complete -C aws_completer aws
  • 認証情報の設定は幾つかありますが、ここではひとまず環境変数にそのまま追記しました。
$ sudo vi .bash_profile
##########################
# aws-cli env.
##########################
export AWS_ACCESS_KEY_ID=<アクセスキーID>
export AWS_SECRET_ACCESS_KEY=<シークレットアクセスキー>

$ source .bash_profile
  • 軽量JSONパーサーツール、『jq』も一緒に入れちゃいましょう。brewコマンドでインストール可能です。
$ brew install jq
==> Downloading http://stedolan.github.io/jq/download/source/jq-1.3.tar.gz
######################################################################## 100.0%
==> ./configure
==> make
/usr/local/Cellar/jq/1.3: 7 files, 268K, built in 8 seconds
$

これでMac上でもawscli&jqを利用出来る様になりました。

$ aws s3 list-buckets | jq '.Buckets[].Name'
"awscli-bucket-acltest"
"awscli-s3bucket"
"awscli-s3bucket-test"
"s3bucket-from-awssdk-groovy"
"s3bucket-from-awssdk-java"
"s3bucket-test"