目次

目次

AWSのCLIは標準出力ではなく標準エラー出力を使っている

高橋克幸
高橋克幸
最終更新日2017/03/14 投稿日2017/03/14

最近 Run Command を利用してAWSのCLIのバージョンを上げる作業をしました。 そのときにCLIの出力が思った通りに動作しなかった為、書きたいと思います.

Run Command の実行

Run Commandではじめに実行したスクリプト以下の内容です。

aws --version
pip install -U awscli
aws --version

実行結果

Collecting awscli
  Downloading awscli-1.11.46-py2.py3-none-any.whl (1.1MB)
Collecting botocore==1.5.9 (from awscli)
  Downloading botocore-1.5.9-py2.py3-none-any.whl (3.3MB)
Requirement already up-to-date: rsa<=3.5.0,>=3.1.2 in /usr/local/lib/python2.7/site-packages (from awscli)
Requirement already up-to-date: s3transfer<0.2.0,>=0.1.9 in /usr/local/lib/python2.7/site-packages (from awscli)
Requirement already up-to-date: colorama<=0.3.7,>=0.2.5 in /usr/local/lib/python2.7/site-packages (from awscli)
Requirement already up-to-date: PyYAML<=3.12,>=3.10 in /usr/local/lib64/python2.7/site-packages (from awscli)
Requirement already up-to-date: docutils>=0.10 in /usr/local/lib/python2.7/site-packages (from awscli)
Requirement already up-to-date: jmespath<1.0.0,>=0.7.1 in /usr/local/lib/python2.7/site-packages (from botocore==1.5.9->awscli)
Requirement already up-to-date: python-dateutil<3.0.0,>=2.1 in /usr/local/lib/python2.7/site-packages (from botocore==1.5.9->awscli)
Collecting pyasn1>=0.1.3 (from rsa<=3.5.0,>=3.1.2->awscli)
  Downloading pyasn1-0.2.2-py2.py3-none-any.whl (51kB)
Requirement already up-to-date: futures<4.0.0,>=2.2.0; python_version == "2.6" or python_version == "2.7" in /usr/local/lib/python2.7/site-packages (from s3transfer<0.2.0,>=0.1.9->awscli)
Requirement already up-to-date: six>=1.5 in /usr/local/lib/python2.7/site-packages (from python-dateutil<3.0.0,>=2.1->botocore==1.5.9->awscli)
Installing collected packages: botocore, awscli, pyasn1
  Found existing installation: botocore 1.5.7
    Uninstalling botocore-1.5.7:
      Successfully uninstalled botocore-1.5.7
  Found existing installation: awscli 1.11.44
    Uninstalling awscli-1.11.44:
      Successfully uninstalled awscli-1.11.44
  Found existing installation: pyasn1 0.2.1
    Uninstalling pyasn1-0.2.1:
      Successfully uninstalled pyasn1-0.2.1
Successfully installed awscli-1.11.46 botocore-1.5.9 pyasn1-0.2.2

----------ERROR-------
aws-cli/1.11.44 Python/2.7.12 Linux/4.4.30-32.54.amzn1.x86_64 botocore/1.5.7
aws-cli/1.11.46 Python/2.7.12 Linux/4.4.30-32.54.amzn1.x86_64 botocore/1.5.9

なぜかエラーにバージョン確認のコマンド結果が表示されてしまいました。

CLIを試す

バージョン確認の結果がエラー出力として表示されていたので、以下のようなコマンドを試してみました。

$ aws --version 1>out.txt 2>error.txt

実行後それぞれのファイルを見てみると、 out.txt には何も出力されておらず、error.txt のファイルを見ると実行結果が出力されていました。

つまり、

AWSCLIのオプション関連の出力は標準出力ではなく標準エラー出力を使っている

ということになります。 エラーではないのに、エラーとして出力されるのはきもちわるいですね。

おわりに

CLIの出力が若干特殊なので、使うときは気をつけましょう。

高橋克幸

新卒3年目で脱新人を目指してます。
フロントに興味を持ち始めた今日このごろ。
趣味は 麻雀 プログラミング 音楽。
運動不足を感じているため、ダンスを始めようかと思っています。

目次