AWS CLIをインストール/設定する
AWS CLI をインストールして、AWS アカウントに CLI で接続できるまで。
参考
概要
インストールした環境
- ProductName: Mac OS X
- ProductVersion: 10.9.4
- BuildVersion: 13E28
インストール結果
- pip 1.5.6
- awscli-1.4.2
- jq-1.3
- yaji 2.0.4
PIP をインストール
PIP は、python のパッケージをインストールするためのパッケージ管理ソフトウェア *1
pip 1.5.6 がインストールされた。
$ sudo easy_install pip
Searching for pip
Reading http://pypi.python.org/simple/pip/
Best match: pip 1.5.6
Downloading https://pypi.python.org/packages/source/p/pip/pip-1.5.6.tar.gz#md5=01026f87978932060cc86c1dc527903e
Processing pip-1.5.6.tar.gz
Running pip-1.5.6/setup.py -q bdist_egg --dist-dir /tmp/easy_install-4_Taj9/pip-1.5.6/egg-dist-tmp-jEYvwJ
warning: no files found matching 'pip/cacert.pem'
warning: no files found matching '*.html' under directory 'docs'
warning: no previously-included files matching '*.rst' found under directory 'docs/_build'
no previously-included directories found matching 'docs/_build/_sources'
Adding pip 1.5.6 to easy-install.pth file
Installing pip script to /usr/local/bin
Installing pip2.7 script to /usr/local/bin
Installing pip2 script to /usr/local/binInstalled /Library/Python/2.7/site-packages/pip-1.5.6-py2.7.egg
Processing dependencies for pip
Finished processing dependencies for pip
AWS CLI をインストールする
install
awscli-1.4.2 がインストールされた。
$ sudo pip install awscli
Downloading/unpacking awscli
Downloading awscli-1.4.2.tar.gz (239kB): 239kB downloaded
Running setup.py (path:/private/tmp/pip_build_root/awscli/setup.py) egg_info for package awscli
Downloading/unpacking botocore>=0.62.0,<0.63.0 (from awscli)
Downloading botocore-0.62.0.tar.gz (2.9MB): 2.9MB downloaded
Running setup.py (path:/private/tmp/pip_build_root/botocore/setup.py) egg_info for package botocore
Downloading/unpacking bcdoc>=0.12.0,<0.13.0 (from awscli)
Downloading bcdoc-0.12.2.tar.gz
Running setup.py (path:/private/tmp/pip_build_root/bcdoc/setup.py) egg_info for package bcdoc
warning: no files found matching 'README.md'
Downloading/unpacking six>=1.1.0 (from awscli)
Downloading six-1.7.3-py2.py3-none-any.whl
Downloading/unpacking colorama==0.2.5 (from awscli)
Downloading colorama-0.2.5.tar.gz
Running setup.py (path:/private/tmp/pip_build_root/colorama/setup.py) egg_info for package colorama
Downloading/unpacking docutils>=0.10 (from awscli)
Downloading docutils-0.12.tar.gz (1.6MB): 1.6MB downloaded
Running setup.py (path:/private/tmp/pip_build_root/docutils/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 rsa==3.1.2 (from awscli)
Downloading rsa-3.1.2.tar.gz
Running setup.py (path:/private/tmp/pip_build_root/rsa/setup.py) egg_info for package rsa
warning: no files found matching 'README'
Downloading/unpacking jmespath==0.4.1 (from botocore>=0.62.0,<0.63.0->awscli)
Downloading jmespath-0.4.1.tar.gz
Running setup.py (path:/private/tmp/pip_build_root/jmespath/setup.py) egg_info for package jmespath
Downloading/unpacking python-dateutil>=2.1 (from botocore>=0.62.0,<0.63.0->awscli)
Downloading python-dateutil-2.2.tar.gz (259kB): 259kB downloaded
Running setup.py (path:/private/tmp/pip_build_root/python-dateutil/setup.py) egg_info for package python-dateutil
Downloading/unpacking pyasn1>=0.1.3 (from rsa==3.1.2->awscli)
Downloading pyasn1-0.1.7.tar.gz (68kB): 68kB downloaded
Running setup.py (path:/private/tmp/pip_build_root/pyasn1/setup.py) egg_info for package pyasn1
Installing collected packages: awscli, botocore, bcdoc, six, colorama, docutils, rsa, jmespath, python-dateutil, pyasn1
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
warning: no files found matching 'README.md'
Running setup.py install for colorama
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 rsa
warning: no files found matching 'README'
Installing pyrsa-encrypt-bigfile script to /usr/local/bin
Installing pyrsa-encrypt script to /usr/local/bin
Installing pyrsa-verify script to /usr/local/bin
Installing pyrsa-sign script to /usr/local/bin
Installing pyrsa-priv2pub script to /usr/local/bin
Installing pyrsa-decrypt script to /usr/local/bin
Installing pyrsa-keygen script to /usr/local/bin
Installing pyrsa-decrypt-bigfile script to /usr/local/bin
Running setup.py install for jmespath
changing mode of build/scripts-2.7/jp from 644 to 755
changing mode of /usr/local/bin/jp to 755
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 pyasn1
Successfully installed awscli botocore bcdoc six colorama docutils rsa jmespath python-dateutil pyasn1
Cleaning up...
jq をインストール
jq-1.3 がインストールされた。
$ sudo 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, 236K, built in 10 seconds
yaji をインストール
JSON フォーマットのベリファイを行うツール。これ絶対ほしい。*4
homebrew を 使って yaji 2.0.4 をインストールする。
$ sudo brew install yajl
==> Installing yajl dependency: cmake
==> Downloading http://www.cmake.org/files/v2.8/cmake-2.8.11.2.tar.gz
######################################################################## 100.0%
==> ./bootstrap --prefix=/usr/local/Cellar/cmake/2.8.11.2 --system-libs --no-sys
==> make
==> make install
🍺 /usr/local/Cellar/cmake/2.8.11.2: 694 files, 32M, built in 4.0 minutes
==> Installing yajl
==> Downloading https://github.com/lloyd/yajl/archive/2.0.4.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/yajl/2.0.4
==> make install
🍺 /usr/local/Cellar/yajl/2.0.4: 15 files, 224K, built in 36 seconds
IAM ユーザを作成する
admin 権限をもつ IAM ユーザに アクセスキーを割り当てる。
手順を書くとこんな感じ。
コマンドラインで利用する際の認証情報ファイルを作成する
Configuring the AWS CLI - AWS Command Line Interface によると、CLI は以下の順番に認証情報を探すらしい。
- 環境変数
- AWS Credential Profile ファイル
- ~/.aws/credentials
- CLI configuration ファイル
- ~/.aws/config
- Instance のプロファイル
参考にした雑誌記事(Software Design (ソフトウェア デザイン) 2014年 06月号 [雑誌])では、3( config )に記載する方法を取っていた。
認証情報だけでなく、CLI で利用したい設定も同一ファイルで定義したいからかな。雑誌の例では、デフォルトリージョンを設定していた。
例に従って、アクセスキー、シークレットアクセスキー、デフォルトリージョンを設定する。
vi とか好みのエディタで編集する場合
~/.aws/config
[default]
aws_access_key_id=xxxxxxxxxx
aws_secret_access_key=xxxxxxxxxxxxxxxxxxxxxxxxregion=us-west-1
aws の configure ツールを使用する場合
aws configure コマンドを実行すると、アクセスキー、シークレットアクセスキー、デフォルトリージョン、デフォルトアウトプットフォーマットを入力するように促される。
$ aws configure
AWS Access Key ID [None]: xxxxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxxxxxxxxxxxxxxxx
Default region name [None]: us-west-1
Default output format [None]:
- Default region には、リージョンとアベイラビリティーゾーン - Amazon Elastic Compute Cloudを参照。
- Default output format には、json, table, text を指定できる。