EC2 RedHat7系にAWS CLIを導入した

EC2 RedHat7系にAWS CLIを導入した:


前提

  • OS: RHEL7系
  • ネットワーク: インターネットアクセスあり
参考にしたサイト https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/installing.html


インストール前の確認

terminal
[ec2-user@ip-10-0-0-197 ~]$ sudo su - 
Last login: Sat Jun 16 15:38:25 UTC 2018 on pts/0 
[root@ip-10-0-0-197 ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.5 (Maipo) 
[root@ip-10-0-0-197 ~]# pip --version 
pip 10.0.1 from /usr/lib/python2.7/site-packages/pip-10.0.1-py2.7.egg/pip (python 2.7) 


インストール

参考サイト通りにpip install awscli --upgrade --userを実行

terminal
[root@ip-10-0-0-197 ~]#  pip install awscli --upgrade --user 
Collecting awscli 
  Downloading https://files.pythonhosted.org/packages/44/48/3712e0bb0c5b7ce66d29a736ffca03af07ad4b8d05c7bc4faea81e1eda1a/awscli-1.15.63-py2.py3-none-any.whl (1.3MB) 
  (長いので省略) 
  The scripts pyrsa-decrypt, pyrsa-decrypt-bigfile, pyrsa-encrypt, pyrsa-encrypt-bigfile, pyrsa-keygen, pyrsa-priv2pub, pyrsa-sign and pyrsa-verify are installed in '/root/.local/bin' which is not on PATH. 
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. 
Successfully installed awscli-1.15.63 botocore-1.10.62 colorama-0.3.9 docutils-0.14 futures-3.2.0 python-dateutil-2.7.3 rsa-3.4.2 s3transfer-0.1.13 
You are using pip version 10.0.1, however version 18.0 is available. 
You should consider upgrading via the 'pip install --upgrade pip' command. 
成功したみたい


それではawsコマンドを叩く

terminal
[root@ip-10-0-0-197 ~]# aws --version 
-bash: aws: command not found 
あれ、失敗した。 とりあえずpip installした場所の状況を確認したい

terminal
[root@ip-10-0-0-197 ~]# pwd 
/root 
[root@ip-10-0-0-197 ~]# ls -la 
total 15784 
dr-xr-x---.  6 root root    4096 Jul 23 20:51 . 
dr-xr-xr-x. 18 root root     236 Mar 23 17:51 .. 
-rw-------.  1 root root    7752 Mar 23 17:52 anaconda-ks.cfg 
-rw-------.  1 root root    2270 Jun 16 17:24 .bash_history 
-rw-r--r--.  1 root root      18 Dec 29  2013 .bash_logout 
-rw-r--r--.  1 root root     176 Dec 29  2013 .bash_profile 
-rw-r--r--.  1 root root     176 Dec 29  2013 .bashrc 
drwx------.  3 root root      17 Jun 15 00:33 .cache 
-rw-r--r--.  1 root root     100 Dec 29  2013 .cshrc 
-rw-r--r--.  1 root root  230136 Oct 29  2017 libtomcrypt-1.17-25.el7.x86_64.rpm 
-rw-r--r--.  1 root root   36304 Oct 29  2017 libtommath-0.42.0-5.el7.x86_64.rpm 
drwx------.  4 root root      28 Jul 23 20:51 .local 
-rw-------.  1 root root    7080 Mar 23 17:52 original-ks.cfg 
drwxr-----.  3 root root      19 Jun 14 04:26 .pki 
-rw-r--r--.  1 root root  487816 Oct 29  2017 python2-crypto-2.6.1-13.el7.x86_64.rpm 
-rw-r--r--.  1 root root  514564 Apr 10 06:34 python2-cryptography-1.7.2-2.el7.x86_64.rpm 
-rw-r--r--.  1 root root   39524 Oct 29  2017 python2-jmespath-0.9.0-1.el7.noarch.rpm 
-rw-r--r--.  1 root root  102192 Nov  8  2017 python2-pyasn1-0.1.9-7.el7.noarch.rpm 
-rw-r--r--.  1 root root  223004 Nov  8  2017 python-cffi-1.6.0-5.el7.x86_64.rpm 
-rw-r--r--.  1 root root   53600 Nov  8  2017 python-enum34-1.0.4-1.el7.noarch.rpm 
-rw-r--r--.  1 root root  118108 Oct 29  2017 python-httplib2-0.9.2-0.1.el7.noarch.rpm 
-rw-r--r--.  1 root root   95908 Nov  8  2017 python-idna-2.4-1.el7.noarch.rpm 
-rw-r--r--.  1 root root  223104 Oct 29  2017 python-keyczar-0.71c-2.el7.noarch.rpm 
-rw-r--r--.  1 root root  274799 Apr 10 19:08 python-paramiko-2.1.1-0.4.el7.noarch.rpm 
-rw-r--r--.  1 root root  125784 Nov  8  2017 python-ply-3.4-11.el7.noarch.rpm 
-rw-r--r--.  1 root root  107052 Nov  8  2017 python-pycparser-2.14-1.el7.noarch.rpm 
-rw-r--r--.  1 root root   72616 Mar  1 00:32 ruby-2.0.0.648-33.el7_4.x86_64.rpm 
-rw-r--r--.  1 root root   84724 Mar  1 00:32 rubygem-bigdecimal-1.2.0-33.el7_4.x86_64.rpm 
-rw-r--r--.  1 root root   55104 Mar  1 00:32 rubygem-io-console-0.4.2-33.el7_4.x86_64.rpm 
-rw-r--r--.  1 root root   81236 Mar  1 00:32 rubygem-json-1.7.7-33.el7_4.x86_64.rpm 
-rw-r--r--.  1 root root   84220 Mar  1 00:32 rubygem-psych-2.0.0-33.el7_4.x86_64.rpm 
-rw-r--r--.  1 root root  329356 Mar  1 00:32 rubygem-rdoc-4.0.0-33.el7_4.noarch.rpm 
-rw-r--r--.  1 root root  224480 Mar  1 00:32 rubygems-2.0.14.1-33.el7_4.noarch.rpm 
-rw-r--r--.  1 root root   94132 Mar  1 00:32 ruby-irb-2.0.0.648-33.el7_4.noarch.rpm 
-rw-r--r--.  1 root root 2931188 Mar  1 00:34 ruby-libs-2.0.0.648-33.el7_4.x86_64.rpm 
drwx------.  2 root root      48 Jun 15 01:39 .ssh 
-rw-r--r--.  1 root root   21848 Oct 29  2017 sshpass-1.06-1.el7.x86_64.rpm 
-rw-r--r--.  1 root root     129 Dec 29  2013 .tcshrc 
rpmってインストールしたあとに必要になることなくね?(エンジニア歴2年の俺の勘がいらないと言っている。 -->rmしとく)

terminal
[root@ip-10-0-0-197 ~]# rm -f *.rpm 
[root@ip-10-0-0-197 ~]# ls -la 
total 260 
dr-xr-x---.  6 root root    255 Jul 23 20:52 . 
dr-xr-xr-x. 18 root root    236 Mar 23 17:51 .. 
-rw-------.  1 root root   7752 Mar 23 17:52 anaconda-ks.cfg 
-rw-------.  1 root root   2270 Jun 16 17:24 .bash_history 
-rw-r--r--.  1 root root     18 Dec 29  2013 .bash_logout 
-rw-r--r--.  1 root root    176 Dec 29  2013 .bash_profile 
-rw-r--r--.  1 root root    176 Dec 29  2013 .bashrc 
drwx------.  3 root root     17 Jun 15 00:33 .cache 
-rw-r--r--.  1 root root    100 Dec 29  2013 .cshrc 
drwx------.  4 root root     28 Jul 23 20:51 .local 
-rw-------.  1 root root   7080 Mar 23 17:52 original-ks.cfg 
drwxr-----.  3 root root     19 Jun 14 04:26 .pki 
drwx------.  2 root root     48 Jun 15 01:39 .ssh 
-rw-r--r--.  1 root root    129 Dec 29  2013 .tcshrc 
pip install したときの出力で以下の部分に気づいた

pip-install
The scripts pyrsa-decrypt, pyrsa-decrypt-bigfile, pyrsa-encrypt, pyrsa-encrypt-bigfile, pyrsa-keygen, pyrsa-priv2pub, pyrsa-sign and pyrsa-verify are installed in '/root/.local/bin' which is not on PATH. 
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location. 
/root/.local/bin/ にawsがありそう

terminal
[root@ip-10-0-0-197 ~]# ./.local/bin/aws --version 
aws-cli/1.15.63 Python/2.7.5 Linux/3.10.0-862.el7.x86_64 botocore/1.10.62 
PATHの行の一番右に:$HOME/.local/binを追加する

terminal
[root@ip-10-0-0-197 ~]# vi .bash_profile 
 
PATH=$PATH:$HOME/bin:$HOME/.local/bin 
bash_profileを変更したので、変更を反映させるには一度ログアウトして、再度ログインする必要がある

以下は再ログイン後に実行

terminal
[ec2-user@ip-10-0-0-197 ~]$ sudo su - 
Last login: Mon Jul 23 20:49:31 UTC 2018 on pts/0 
[root@ip-10-0-0-197 ~]# aws --version 
aws-cli/1.15.63 Python/2.7.5 Linux/3.10.0-862.el7.x86_64 botocore/1.10.62 
できました。

コメント