AWS大好きっ子アピールをしておきながら実は仕事以外では全然使っていません。
これでは車好きだと言いながら自転車に乗っているようなものなので、もっとAWSっ子になるために修行がてらブログの引っ越しをしてみようかと思います。
せっかくなので最近話題のDockerとかいうのも触ってみようかと。
前提作業
アカウント作成は、事前にしておいたので今回は省略します。
初めての方はクラスメソッド様のブログを参考にすると良いでしょう。
http://dev.classmethod.jp/cloud/aws/after_get_aws_account/
AWS CLIをインスコする
さて、初歩の初歩からですが、とりあえずAWS CLIを使えるようにします。
今回はMacなので、まずeasy_installでpipをインストールします。
ちなみにMacの場合、easy_installはデフォルトでインストールされているらしいです。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
$ sudo easy_install pip Password: Searching for pip Reading https://pypi.python.org/simple/pip/ Best match: pip 8.1.2 Downloading https://pypi.python.org/packages/e7/a8/7556133689add8d1a54c0b14aeff0acb03c64707ce100ecd53934da1aa13/pip-8.1.2.tar.gz#md5=87083c0b9867963b29f7aba3613e8f4a Processing pip-8.1.2.tar.gz Writing /tmp/easy_install-P29ZlP/pip-8.1.2/setup.cfg Running pip-8.1.2/setup.py -q bdist_egg --dist-dir /tmp/easy_install-P29ZlP/pip-8.1.2/egg-dist-tmp-EEmy0_ warning: no previously-included files found matching '.coveragerc' warning: no previously-included files found matching '.mailmap' warning: no previously-included files found matching '.travis.yml' warning: no previously-included files found matching '.landscape.yml' warning: no previously-included files found matching 'pip/_vendor/Makefile' warning: no previously-included files found matching 'tox.ini' warning: no previously-included files found matching 'dev-requirements.txt' warning: no previously-included files found matching 'appveyor.yml' no previously-included directories found matching '.github' no previously-included directories found matching '.travis' no previously-included directories found matching 'docs/_build' no previously-included directories found matching 'contrib' no previously-included directories found matching 'tasks' no previously-included directories found matching 'tests' Adding pip 8.1.2 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/bin Installed /Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg Processing dependencies for pip Finished processing dependencies for pip |
ふむふむ、さくっとインスコされました。
続いてAWS CLIをインスコします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
$ sudo pip install awscli The directory '/Users/hoge/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/Users/hoge/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Collecting awscli Downloading awscli-1.10.28-py2.py3-none-any.whl (937kB) 100% |████████████████████████████████| 942kB 1.2MB/s Collecting rsa<=3.3.0,>=3.1.2 (from awscli) Downloading rsa-3.3-py2.py3-none-any.whl (44kB) 100% |████████████████████████████████| 51kB 6.8MB/s Collecting docutils>=0.10 (from awscli) Downloading docutils-0.12.tar.gz (1.6MB) 100% |████████████████████████████████| 1.6MB 686kB/s Collecting botocore==1.4.19 (from awscli) Downloading botocore-1.4.19-py2.py3-none-any.whl (2.3MB) 100% |████████████████████████████████| 2.3MB 489kB/s Collecting s3transfer==0.0.1 (from awscli) Downloading s3transfer-0.0.1-py2.py3-none-any.whl Collecting colorama<=0.3.3,>=0.2.5 (from awscli) Downloading colorama-0.3.3.tar.gz Collecting pyasn1>=0.1.3 (from rsa<=3.3.0,>=3.1.2->awscli) Downloading pyasn1-0.1.9-py2.py3-none-any.whl Collecting python-dateutil<3.0.0,>=2.1 (from botocore==1.4.19->awscli) Downloading python_dateutil-2.5.3-py2.py3-none-any.whl (201kB) 100% |████████████████████████████████| 204kB 4.2MB/s Collecting jmespath<1.0.0,>=0.7.1 (from botocore==1.4.19->awscli) Downloading jmespath-0.9.0-py2.py3-none-any.whl Collecting futures<4.0.0,>=2.2.0; python_version == "2.6" or python_version == "2.7" (from s3transfer==0.0.1->awscli) Downloading futures-3.0.5-py2-none-any.whl Collecting six>=1.5 (from python-dateutil<3.0.0,>=2.1->botocore==1.4.19->awscli) Downloading six-1.10.0-py2.py3-none-any.whl Installing collected packages: pyasn1, rsa, docutils, six, python-dateutil, jmespath, botocore, futures, s3transfer, colorama, awscli Running setup.py install for docutils ... done Found existing installation: six 1.4.1 DEPRECATION: Uninstalling a distutils installed project (six) has been deprecated and will be removed in a future version. This is due to the fact that uninstalling a distutils project will only partially uninstall the project. Uninstalling six-1.4.1: Exception: Traceback (most recent call last): File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/basecommand.py", line 215, in main status = self.run(options, args) File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/commands/install.py", line 317, in run prefix=options.prefix_path, File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_set.py", line 736, in install requirement.uninstall(auto_confirm=True) File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_install.py", line 742, in uninstall paths_to_remove.remove(auto_confirm) File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/req/req_uninstall.py", line 115, in remove renames(path, new_path) File "/Library/Python/2.7/site-packages/pip-8.1.2-py2.7.egg/pip/utils/__init__.py", line 267, in renames shutil.move(old, new) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 302, in move copy2(src, real_dst) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 131, in copy2 copystat(src, dst) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/shutil.py", line 103, in copystat os.chflags(dst, st.st_flags) OSError: [Errno 1] Operation not permitted: '/tmp/pip-k2Okce-uninstall/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/six-1.4.1-py2.7.egg-info' |
なんかエラーでしたが、Sixとかいうものを消そうとしているようですが、そんなもの存在しないよ。っていう事らしいです。
なので、–ignore-installed sixとつけて再度実行してみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
$ sudo pip install awscli --ignore-installed six The directory '/Users/motoki/Library/Caches/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. The directory '/Users/motoki/Library/Caches/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag. Collecting awscli Downloading awscli-1.10.28-py2.py3-none-any.whl (937kB) 100% |████████████████████████████████| 942kB 1.3MB/s Collecting six Downloading six-1.10.0-py2.py3-none-any.whl Collecting rsa<=3.3.0,>=3.1.2 (from awscli) Downloading rsa-3.3-py2.py3-none-any.whl (44kB) 100% |████████████████████████████████| 51kB 6.4MB/s Collecting docutils>=0.10 (from awscli) Downloading docutils-0.12.tar.gz (1.6MB) 100% |████████████████████████████████| 1.6MB 806kB/s Collecting botocore==1.4.19 (from awscli) Downloading botocore-1.4.19-py2.py3-none-any.whl (2.3MB) 100% |████████████████████████████████| 2.3MB 529kB/s Collecting s3transfer==0.0.1 (from awscli) Downloading s3transfer-0.0.1-py2.py3-none-any.whl Collecting colorama<=0.3.3,>=0.2.5 (from awscli) Downloading colorama-0.3.3.tar.gz Collecting pyasn1>=0.1.3 (from rsa<=3.3.0,>=3.1.2->awscli) Downloading pyasn1-0.1.9-py2.py3-none-any.whl Collecting python-dateutil<3.0.0,>=2.1 (from botocore==1.4.19->awscli) Downloading python_dateutil-2.5.3-py2.py3-none-any.whl (201kB) 100% |████████████████████████████████| 204kB 4.4MB/s Collecting jmespath<1.0.0,>=0.7.1 (from botocore==1.4.19->awscli) Downloading jmespath-0.9.0-py2.py3-none-any.whl Collecting futures<4.0.0,>=2.2.0; python_version == "2.6" or python_version == "2.7" (from s3transfer==0.0.1->awscli) Downloading futures-3.0.5-py2-none-any.whl Installing collected packages: pyasn1, rsa, docutils, six, python-dateutil, jmespath, botocore, futures, s3transfer, colorama, awscli Running setup.py install for docutils ... done Running setup.py install for colorama ... done Successfully installed awscli-1.10.28 botocore-1.4.19 colorama-0.3.3 docutils-0.12 futures-3.0.5 jmespath-0.9.0 pyasn1-0.1.9 python-dateutil-1.5 rsa-3.3 s3transfer-0.0.1 six-1.4.1 |
いけました。
一応ちゃんとインストールされたことを確認します。
1 2 3 4 5 |
$ which aws /usr/local/bin/aws $ aws --v shell-init: error retrieving current directory: getcwd: cannot access parent directories: No such file or directory aws-cli/1.10.28 Python/2.7.10 Darwin/15.4.0 botocore/1.4.19 |
AWS CLIの初期設定
続いてAWS CLIで操作する対象となるIAMユーザーの認証情報を設定します。
aws configureを実行すると対話的に入力が可能です。
- 下記AccessKeyとSecretAccessKeyはマネジメントコンソールのIAM管理画面より取得します。
利用するユーザの権限設定を忘れているとCLIでコマンド実行ができないので注意しましょう。 - region nameには、使いたいリージョンを指定します。リージョン名は下記リンクを参考に。
https://docs.aws.amazon.com/ja_jp/general/latest/gr/rande.html - output formatには、コマンド実行結果の表示形式を入力します。今回はとりあえずtextを設定します。
1 2 3 4 5 |
$ aws configure AWS Access Key ID [None]: AKI**************** AWS Secret Access Key [None]: ***************** Default region name [None]: us-west-2 Default output format [None]: text |
AWS CLI動作確認
ためしにS3のバケットを作成してみます。
1 2 3 4 5 |
$ aws s3 mb s3://backetname-XXXXX make_bucket: s3://backetname-XXXXX/ $ aws s3 ls 2016-05-XX XX:XX:XX cloudtail-XXXXX 2016-05-XX XX:XX:XX backetname-XXXXX |
無事AWS CLIでバケットが作成できました。
今回はとりあえずここまでで。続きはまたゆっくりやっていきます。
ちなみにこの手順はクラスメソッド様のブログを参考にしまくっていますので、より詳細な解説は以下ページをご覧ください。
http://dev.classmethod.jp/cloud/aws/mac-aws-cli/