読者です 読者をやめる 読者になる 読者になる

日々充実

毎日が充実したと思えるようになるためのブログ

【備忘録】Cloud9 IDEへのAWS CLIインストール

Cloud9 AWS 備忘録

こんばんわ、ヒサユキですヽ(=´▽`=)ノ
久々に長時間ハマったので、備忘録残します・・・(;´∀`)

タイトルの通りCloud9 IDEへのAWS CLIインストールについてです!

先に結論言っちゃいます

このQiitaの記事のやり方だけで行けました。
Cloud9とAWSで検索しまくってたので、最初見つからなかったです・・・
qiita.com

ここからは経緯も含めて、備忘録書いていきます。

経緯

今Cloud9 IDEで作ったサンプルファイルを一旦Macに落として、それからS3にあげてます。
これが手間なので、Cloud9 IDEからCLIで直接S3に転送したいと思いました。
もちろん、Cloud9 IDEはパブリックスペース使ってるのでIAMのアクセスキーとかは都度発行になりますがw

躓いたとこ

pipのバージョン

バージョンが古いことで、CLIがインストールできないという記事をみたので
Cloud9のpipのバージョンを確認してみた。

pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)

古い・・・・最新バージョンはpip-9.0.1
とりあえず、バージョンを上げてみる。

$sudo pip install --upgrade pip
Downloading/unpacking pip from https://pypi.python.org/packages/b6/ac/7015eb97dc749283ffdec1c3a88ddb8ae03b8fad0f0e611408f196358da3/pip-9.0.1-py2.py3-none-any.whl#md5=297dbd16ef53bcef0447d245815f5144
  Downloading pip-9.0.1-py2.py3-none-any.whl (1.3MB): 1.3MB downloaded
Installing collected packages: pip
  Found existing installation: pip 1.5.4
    Not uninstalling pip at /usr/lib/python2.7/dist-packages, owned by OS
Successfully installed pip
Cleaning up...

失敗した。/usr/lib/python2.7/dist-packagesが消せないよと言われている。
ただ、/usr/local/lib/python2.7/dist-packages/pip-9.0.1.dist-infoにはダウンロード出来ている。
なので以下のコマンドで変えてみました。

sudo rm -r /usr/lib/python2.7/dist-packages/pip
sudo cp -r /usr/local/lib/python2.7/dist-packages/pip-9.0.1.dist-info/ /usr/lib/python2.7/dist-packages
sudo mv /usr/lib/python2.7/dist-packages/pip-9.0.1.dist-info/ /usr/lib/python2.7/dist-packages/pip 

バージョンを確認すると、9.0.1に変わった。

pip 9.0.1 from /usr/local/lib/python2.7/dist-packages (python 2.7)

これで行けると思い、インストールしてみたところ・・・

    creating build/temp.linux-x86_64-2.7
    checking if libyaml is compilable
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c build/temp.linux-x86_64-2.7/check_libyaml.c -o build/temp.linux-x86_64-2.7/check_libyaml.o
    checking if libyaml is linkable
    x86_64-linux-gnu-gcc -pthread build/temp.linux-x86_64-2.7/check_libyaml.o -lyaml -o build/temp.linux-x86_64-2.7/check_libyaml
    building '_yaml' extension
    creating build/temp.linux-x86_64-2.7/ext
    x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c ext/_yaml.c -o build/temp.linux-x86_64-2.7/ext/_yaml.o
    ext/_yaml.c:4:20: fatal error: Python.h: No such file or directory
     #include "Python.h"
                        ^
    compilation terminated.
    error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
    
    ----------------------------------------
Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-FvuI49/PyYAML/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-OsVbw7-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-FvuI49/PyYAML/
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.

どうやらpipのバージョンだけではいけないことがわかった

python2.7-devのインストール

error: Python.h: No such file or directoryのエラーについては
python2.7-devをインストールすれば治るということで、インストールを試みる。

$ sudo apt-get install python2.7-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package python2.7-dev
E: Couldn't find any package by regex 'python2.7-dev'

失敗した(;´∀`)

これについては、最初ほんとにわからなかった。
そもそも1行のapt-getコマンドだけだし、python2.7-devが見つからないってどういうこと?

調べていった結果、apt-getのバージョンに問題があった模様・・・・

apt-getのバージョンアップ

というわけで、アップデートコマンドを打ってみる。

$ sudo apt-get update
Ign http://downloads-distro.mongodb.org dist InRelease
Get:1 http://security.ubuntu.com trusty-security InRelease [65.9 kB]           
Get:2 http://ppa.launchpad.net trusty InRelease [15.5 kB]                      
Hit http://downloads-distro.mongodb.org dist Release.gpg                       
Ign http://asia-east1.gce.clouds.archive.ubuntu.com trusty InRelease           
Get:3 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates InRelease [65.9 kB]
Get:4 http://ppa.launchpad.net trusty InRelease [15.4 kB]                      
Hit http://downloads-distro.mongodb.org dist Release                           
Ign http://toolbelt.heroku.com ./ InRelease                                    
Get:5 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports InRelease [65.9 kB]
Get:6 http://security.ubuntu.com trusty-security/main Sources [158 kB]         
Get:7 http://ppa.launchpad.net trusty/main amd64 Packages [23.2 kB]            
Get:8 http://toolbelt.heroku.com ./ Release.gpg [473 B]                        
Hit http://downloads-distro.mongodb.org dist/10gen amd64 Packages              
Get:9 http://asia-east1.gce.clouds.archive.ubuntu.com trusty Release.gpg [933 B]
Get:10 http://toolbelt.heroku.com ./ Release [1609 B]                          
Get:11 http://security.ubuntu.com trusty-security/universe Sources [57.6 kB]   
Get:12 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates/main Sources [483 kB]
Get:13 http://ppa.launchpad.net trusty/main i386 Packages [23.2 kB]            
Hit http://downloads-distro.mongodb.org dist/10gen i386 Packages               
Get:14 http://security.ubuntu.com trusty-security/main amd64 Packages [718 kB] 
Get:15 http://toolbelt.heroku.com ./ Packages [721 B]                          
Get:16 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates/restricted Sources [5957 B]
Get:17 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates/universe Sources [218 kB]
Get:18 http://security.ubuntu.com trusty-security/universe amd64 Packages [197 kB]
Get:19 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates/multiverse Sources [7375 B]
Get:20 http://security.ubuntu.com trusty-security/main i386 Packages [667 kB]  
Get:21 http://ppa.launchpad.net trusty/main amd64 Packages [3424 B]            
Get:22 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates/main amd64 Packages [1180 kB]
Get:23 http://ppa.launchpad.net trusty/main i386 Packages [3425 B]             
Get:24 http://security.ubuntu.com trusty-security/universe i386 Packages [197 kB]
Get:25 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates/restricted amd64 Packages [20.4 kB]
Get:26 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates/universe amd64 Packages [513 kB]
Get:27 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates/multiverse amd64 Packages [15.2 kB]
Get:28 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates/main i386 Packages [1127 kB]
Get:29 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates/restricted i386 Packages [20.1 kB]
Get:30 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates/universe i386 Packages [515 kB]
Get:31 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-updates/multiverse i386 Packages [15.8 kB]
Get:32 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports/main Sources [10.3 kB]
Get:33 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports/restricted Sources [40 B]
Get:34 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports/universe Sources [41.2 kB]
Get:35 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports/multiverse Sources [1751 B]
Get:36 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports/main amd64 Packages [14.8 kB]
Get:37 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports/restricted amd64 Packages [40 B]
Get:38 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports/universe amd64 Packages [52.6 kB]
Get:39 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports/multiverse amd64 Packages [1396 B]
Get:40 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports/main i386 Packages [14.8 kB]
Get:41 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports/restricted i386 Packages [40 B]
Get:42 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports/universe i386 Packages [52.5 kB]
Get:43 http://asia-east1.gce.clouds.archive.ubuntu.com trusty-backports/multiverse i386 Packages [1381 B]
Get:44 http://asia-east1.gce.clouds.archive.ubuntu.com trusty Release [58.5 kB]
Get:45 http://asia-east1.gce.clouds.archive.ubuntu.com trusty/main Sources [1335 kB]
Get:46 http://asia-east1.gce.clouds.archive.ubuntu.com trusty/restricted Sources [5335 B]
Get:47 http://asia-east1.gce.clouds.archive.ubuntu.com trusty/universe Sources [7926 kB]
Get:48 http://asia-east1.gce.clouds.archive.ubuntu.com trusty/multiverse Sources [211 kB]
Get:49 http://asia-east1.gce.clouds.archive.ubuntu.com trusty/main amd64 Packages [1743 kB]
Get:50 http://asia-east1.gce.clouds.archive.ubuntu.com trusty/restricted amd64 Packages [16.0 kB]
Get:51 http://asia-east1.gce.clouds.archive.ubuntu.com trusty/universe amd64 Packages [7589 kB]
Get:52 http://asia-east1.gce.clouds.archive.ubuntu.com trusty/multiverse amd64 Packages [169 kB]
Get:53 http://asia-east1.gce.clouds.archive.ubuntu.com trusty/main i386 Packages [1739 kB]
Get:54 http://asia-east1.gce.clouds.archive.ubuntu.com trusty/restricted i386 Packages [16.4 kB]
Get:55 http://asia-east1.gce.clouds.archive.ubuntu.com trusty/universe i386 Packages [7597 kB]
Get:56 http://asia-east1.gce.clouds.archive.ubuntu.com trusty/multiverse i386 Packages [172 kB]
Fetched 35.2 MB in 16s (2151 kB/s)                                             
Reading package lists... Done

なんか一気にいろいろとパッケージが入ってきたので、
再度sudo apt-get install python2.7-devコマンド

$ sudo apt-get install python2.7-dev
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libpython2.7 libpython2.7-dev libpython2.7-minimal libpython2.7-stdlib
  python2.7 python2.7-minimal
Suggested packages:
  python2.7-doc binfmt-support
The following NEW packages will be installed:
  libpython2.7-dev python2.7-dev
The following packages will be upgraded:
  libpython2.7 libpython2.7-minimal libpython2.7-stdlib python2.7
  python2.7-minimal
5 upgraded, 2 newly installed, 0 to remove and 155 not upgraded.
Need to get 26.9 MB of archives.
After this operation, 34.1 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main python2.7 amd64 2.7.6-8ubuntu0.3 [197 kB]
Get:2 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main libpython2.7 amd64 2.7.6-8ubuntu0.3 [1039 kB]
Get:3 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main libpython2.7-stdlib amd64 2.7.6-8ubuntu0.3 [1873 kB]
Get:4 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main python2.7-minimal amd64 2.7.6-8ubuntu0.3 [1187 kB]
Get:5 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main libpython2.7-minimal amd64 2.7.6-8ubuntu0.3 [307 kB]
Get:6 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main libpython2.7-dev amd64 2.7.6-8ubuntu0.3 [22.0 MB]
Get:7 http://asia-east1.gce.clouds.archive.ubuntu.com/ubuntu/ trusty-updates/main python2.7-dev amd64 2.7.6-8ubuntu0.3 [269 kB]
Fetched 26.9 MB in 6s (4094 kB/s)                                              
(Reading database ... 74739 files and directories currently installed.)
Preparing to unpack .../python2.7_2.7.6-8ubuntu0.3_amd64.deb ...
Unpacking python2.7 (2.7.6-8ubuntu0.3) over (2.7.6-8ubuntu0.2) ...
Preparing to unpack .../libpython2.7_2.7.6-8ubuntu0.3_amd64.deb ...
Unpacking libpython2.7:amd64 (2.7.6-8ubuntu0.3) over (2.7.6-8ubuntu0.2) ...
Preparing to unpack .../libpython2.7-stdlib_2.7.6-8ubuntu0.3_amd64.deb ...
Unpacking libpython2.7-stdlib:amd64 (2.7.6-8ubuntu0.3) over (2.7.6-8ubuntu0.2) ...
Preparing to unpack .../python2.7-minimal_2.7.6-8ubuntu0.3_amd64.deb ...
Unpacking python2.7-minimal (2.7.6-8ubuntu0.3) over (2.7.6-8ubuntu0.2) ...
Preparing to unpack .../libpython2.7-minimal_2.7.6-8ubuntu0.3_amd64.deb ...
Unpacking libpython2.7-minimal:amd64 (2.7.6-8ubuntu0.3) over (2.7.6-8ubuntu0.2) ...
Selecting previously unselected package libpython2.7-dev:amd64.
Preparing to unpack .../libpython2.7-dev_2.7.6-8ubuntu0.3_amd64.deb ...
Unpacking libpython2.7-dev:amd64 (2.7.6-8ubuntu0.3) ...
Selecting previously unselected package python2.7-dev.
Preparing to unpack .../python2.7-dev_2.7.6-8ubuntu0.3_amd64.deb ...
Unpacking python2.7-dev (2.7.6-8ubuntu0.3) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for desktop-file-utils (0.22-1ubuntu1) ...
Processing triggers for mime-support (3.54ubuntu1.1) ...
Setting up libpython2.7-minimal:amd64 (2.7.6-8ubuntu0.3) ...
Setting up python2.7-minimal (2.7.6-8ubuntu0.3) ...
Setting up libpython2.7-stdlib:amd64 (2.7.6-8ubuntu0.3) ...
Setting up python2.7 (2.7.6-8ubuntu0.3) ...
Setting up libpython2.7:amd64 (2.7.6-8ubuntu0.3) ...
Setting up libpython2.7-dev:amd64 (2.7.6-8ubuntu0.3) ...
Setting up python2.7-dev (2.7.6-8ubuntu0.3) ...
Processing triggers for libc-bin (2.19-0ubuntu6.6) ...

やっと成功したヽ(=´▽`=)ノ

この流れで、sudo pip install awscliもやってみた

sudo pip install awscli
The directory '/home/ubuntu/.cache/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 '/home/ubuntu/.cache/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
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:318: SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#snimissingwarning.
  SNIMissingWarning
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning
  Downloading awscli-1.11.44-py2.py3-none-any.whl (1.1MB)
    100% |████████████████████████████████| 1.1MB 904kB/s 
Collecting PyYAML<=3.12,>=3.10 (from awscli)
  Downloading PyYAML-3.12.tar.gz (253kB)
    100% |████████████████████████████████| 256kB 2.7MB/s 
Requirement already satisfied: colorama<=0.3.7,>=0.2.5 in /usr/lib/python2.7/dist-packages (from awscli)
Requirement already satisfied: docutils>=0.10 in /usr/local/lib/python2.7/dist-packages (from awscli)
Collecting s3transfer<0.2.0,>=0.1.9 (from awscli)
  Downloading s3transfer-0.1.10-py2.py3-none-any.whl (54kB)
    100% |████████████████████████████████| 61kB 5.1MB/s 
Collecting rsa<=3.5.0,>=3.1.2 (from awscli)
  Downloading rsa-3.4.2-py2.py3-none-any.whl (46kB)
    100% |████████████████████████████████| 51kB 7.0MB/s 
Requirement already satisfied: botocore==1.5.7 in /usr/local/lib/python2.7/dist-packages (from awscli)
Collecting futures<4.0.0,>=2.2.0; python_version == "2.6" or python_version == "2.7" (from s3transfer<0.2.0,>=0.1.9->awscli)
  Downloading futures-3.0.5-py2-none-any.whl
Collecting pyasn1>=0.1.3 (from rsa<=3.5.0,>=3.1.2->awscli)
  Downloading pyasn1-0.2.1-py2.py3-none-any.whl (51kB)
    100% |████████████████████████████████| 61kB 8.8MB/s 
Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in /usr/local/lib/python2.7/dist-packages (from botocore==1.5.7->awscli)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /usr/local/lib/python2.7/dist-packages (from botocore==1.5.7->awscli)
Requirement already satisfied: six>=1.5 in /usr/lib/python2.7/dist-packages (from python-dateutil<3.0.0,>=2.1->botocore==1.5.7->awscli)
Installing collected packages: PyYAML, futures, s3transfer, pyasn1, rsa, awscli
  Running setup.py install for PyYAML ... done
Successfully installed PyYAML-3.12 awscli-1.11.44 futures-3.0.5 pyasn1-0.2.1 rsa-3.4.2 s3transfer-0.1.10
/usr/local/lib/python2.7/dist-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:122: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/security.html#insecureplatformwarning.
  InsecurePlatformWarning

こっちも成功したヽ(=´▽`=)ノ

結局どこから必要だったのか

最初の結論に戻りますが・・・

sudo apt-get update
sudo apt-get install python2.7-dev
sudo pip install awscli

こんだけです。
pipバージョンは古いままで行けました、なので一番最初の作業いりません/(^o^)\
pipバージョンUPだけでも結構時間使ったけどなぁ・・・・orz

まとめ

最後のチェックでaws --version叩いたらちゃんと結果帰ってきました

$ aws --version
aws-cli/1.11.44 Python/2.7.6 Linux/4.8.2-c9 botocore/1.5.7

情報少なかったけど、ちゃっとCloud9 IDEにもAWS CLIは入ります!!
今プライベートプロジェクトは別で使用しているので、今回はパブリックプロジェクトでやりました。
無料分でも一つはプライベートプロジェクト作れるので、IAMで専用ユーザ切って当ててあげればいいかなと
そうすれば都度都度、アクセスキー発行しなくてもいいかもですね。

今回躓いた要因としては、単純にUbuntuCLIを入れるって考えで探せばよかったのですが、
Cloud9 IDEに入れることに意識が行ってしまったのが時間かかったところですね・・・

とりあえずやりたかったS3への直接転送は出来ました!
今、Webサイト公開までCLIコマンドで出来たのであとはバケットポリシーをJSONで書いて、
それをバケットに当てるところまではやりたいです!