CentOS7
CentOS7環境にaws-cliを入れるまでの作業メモです。
aws-cliは、Python2.6.5以上またはPython 3.3以上で動くようです。
CentOS7ならデフォルトで2.7.5が入ってるので、インストールが楽です。(CentOS6だとpythonのバージョンアップ作業が必要で後々めんどくさいです)
インストール手順は、下記見れば分かるんですが自分用メモです。
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/awscli-install-linux.html#awscli-install-linux-path
1.pipインストール
# curl -kL https://bootstrap.pypa.io/get-pip.py | python
# pip install awscli --upgrade --user
2.パス設定
# vi ~/.bash_profile
追加:
export PATH=~/.local/bin:$PATH
# source ~/.bash_profile
3.AWS認証設定
アクセスキーとシークレットキーは、下記で作成します。
https://console.aws.amazon.com/iam/home?#/security_credential
# aws configure
AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [None]: ap-northeast-1
Default output format [None]: json
終わり。
CentOS6
CentoS6環境にaws-cliを入れるまでの作業メモです。
環境
CentOS6.7
※Vagrant環境でマッサラ状態からのスタートです。
pyenvインストール
デフォルトで入っているpythonのバージョンが2.6だったので
pythonのバージョンアップからスタートします。
下記を参考にしています。
http://uorat.hatenablog.com/entry/2016/02/03/131534
2.6の状態でインストールしようとしてもエラーが起きます。
# sudo pip install awscli
DEPRECATION: Python 2.6 is no longer supported by the Python core team, please upgrade your Python. A future version of pip will drop support for Python 2.6
.
.
.
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-J9NXPb/PyYAML/
インストール
# git clone https://github.com/yyuu/pyenv.git ~/.pyenv
環境変数の設定
# echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
# echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
# echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
# source ~/.bash_profile
zlibインストール
# pyenv install 3.6.0
can't decompress data; zlib not available
zlibがないと怒られたのでインストール
# yum install -y zlib-devel
bzip2 / readline-devel / sqlite3 / openssl-devel インストール
# pyenv install 3.6.0
WARNING: The Python bz2 extension was not compiled. Missing the bzip2 lib?
WARNING: The Python readline extension was not compiled. Missing the GNU readline lib?
ERROR: The Python ssl extension was not compiled. Missing the OpenSSL lib?
上記必要なものが入ってないとの事なので、下記参考にインストール
http://kite03.hatenablog.com/entry/2014/07/24/005337
https://github.com/pyenv/pyenv/wiki/Common-build-problems
# sudo yum install bzip2 bzip2-devel readline-devel sqlite3 sqlite-devel openssl-devel
python3.6.0に切り替え
結局色々頑張ってみたのですが、下記ワーニングは消えませんでした。(うーん、、、)
が、インストールは出来ているようです。
# pyenv install 3.6.0
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?
Installed Python-3.6.0 to /root/.pyenv/versions/3.6.0
python 3.6.0に切り替えます。
# pyenv global 3.6.0
# pyenv version
3.6.0 (set by /root/.pyenv/version)
# python --version
Python 3.6.0
aws-cliのインストール
# pip install awscli --upgrade --user
下記を参考にインストールし、成功しました。
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/awscli-install-linux.html
パスを通す
インストールしただけだと、awsコマンドが認識されなかったのでパスを通します。
下記を開いて、PATHに「~/.local/bin」を追加して下さい。
# vi ~/.bash_profile
末尾に下記を追加します。
PATH=$PATH:~/.local/bin
変更を反映します。
# source ~/.bash_profile
awsのバージョンの表示に成功しました。
# aws --version
aws-cli/1.14.18 Python/3.6.0 Linux/2.6.32-573.7.1.el6.x86_64 botocore/1.8.22
aws認証情報の設定
awsコマンドでAWSにアクセスする際に必要となる認証情報を設定します。
(環境変数に設定する方法もあるようですが)
# aws configure
アクセスキーとシークレットキーは、下記で作成します。
https://console.aws.amazon.com/iam/home?#/security_credential
生成されたアクセスキーとシークレットキーを入力します。
「ap-northeast-1」は東京リージョン、ouput formatは出力形式です。
# aws configure
AWS Access Key ID [None]:
AWS Secret Access Key [None]:
Default region name [None]: ap-northeast-1
Default output format [None]: json
「~/.aws」ディレクトリに認証情報が生成されます。