ImportError: cannot import name 'AliasedEventEmitter'

# 概要

* pythonの処理を含むツールが動かなくなった
* python２系で動いていたもの
* 処理はawsのｓ３コマンドでアップロードするというもの
* ツールは改変・改修していない
* API側の対応が変わったのかと推測
* Python２系では”pyenv: aws: command not found”エラー
* Python３系では”ImportError: cannot import name 'AliasedEventEmitter'”が出力された
* クライアント側の対応で無事修正

# Python２系で実行してみる

```
$ pyenv global 2.7.15
$ python -V
Python 2.7.15
$ bash -x ObjectStorageUpload.sh feature/20191019
:
+ eval '~/.pyenv/shims/aws
:
pyenv: aws: command not found

The `aws' command exists in these Python versions:
  3.6.5

python2.7.15バージョンではawsコマンドが見つからないらしい

$ which aws
~/.pyenv/shims/aws

あるけど。。
```

# Python３系で実行してみる

```
$ pyenv global 3.6.5
$ python -V
Python 3.6.5
$ bash -x ObjectStorageUpload.sh feature/20191019
:
Traceback (most recent call last):
  File "/home/appuser/.pyenv/versions/3.6.5/bin/aws", line 19, in <module>
    import awscli.clidriver
  File "/home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages/awscli/clidriver.py", line 19, in <module>
    from botocore.hooks import AliasedEventEmitter
ImportError: cannot import name 'AliasedEventEmitter'

--------------------------------------------------------
botocoreのAliasedEventEmitterというライブラリがimportエラーとなる
おそらくAPI側がアップデートされ対応しなくなったと推測
クライアント側を新しくし、復帰を試みる
```

# クライアント側アップデート

### pipをアップグレード

```
$ pyenv global 3.6.5
$ python -m pip install --upgrade pip
Collecting pip
  Using cached https://files.pythonhosted.org/packages/4a/08/6ca123073af4ebc4c5488a5bc8a010ac57aa39ce4d3c8a931ad504de4185/pip-19.3-py2.py3-none-any.whl
Installing collected packages: pip
  Found existing installation: pip 19.2.3
    Uninstalling pip-19.2.3:
      Successfully uninstalled pip-19.2.3
Successfully installed pip-19.3
```

### awscliをアンインストール

```
$ pip uninstall awscli
Uninstalling awscli-1.15.85:
  Would remove:
    /home/appuser/.pyenv/versions/3.6.5/bin/aws
    /home/appuser/.pyenv/versions/3.6.5/bin/aws.cmd
    /home/appuser/.pyenv/versions/3.6.5/bin/aws_bash_completer
    /home/appuser/.pyenv/versions/3.6.5/bin/aws_completer
    /home/appuser/.pyenv/versions/3.6.5/bin/aws_zsh_completer.sh
    /home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages/awscli-1.15.85.dist-info/*
    /home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages/awscli/*
Proceed (y/n)? y
  Successfully uninstalled awscli-1.15.85
```

### awscliを再インストール

```
$ pip install awscli
Collecting awscli
  Downloading https://files.pythonhosted.org/packages/78/10/c6cb48997dade2efcf6007ee72a46302fe3313ed26fd0f04499da3c64679/awscli-1.16.259-py2.py3-none-any.whl (2.3MB)
     |████████████████████████████████| 2.3MB 20.6MB/s
Collecting botocore==1.12.249
  Downloading https://files.pythonhosted.org/packages/1a/c3/1f414af36a62df9f4a5a4d0ff094ab3f73a0a696d3228ab41c94f302cf93/botocore-1.12.249-py2.py3-none-any.whl (5.7MB)
     |████████████████████████████████| 5.7MB 42.1MB/s
Requirement already satisfied: rsa<=3.5.0,>=3.1.2 in /home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from awscli) (3.4.2)
Requirement already satisfied: docutils<0.16,>=0.10 in /home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from awscli) (0.15.2)
Requirement already satisfied: s3transfer<0.3.0,>=0.2.0 in /home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from awscli) (0.2.1)
Requirement already satisfied: PyYAML<5.2,>=3.10; python_version != "2.6" and python_version != "3.3" in /home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from awscli) (3.13)
Requirement already satisfied: colorama<0.4.2,>=0.2.5; python_version != "2.6" and python_version != "3.3" in /home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from awscli) (0.3.9)
Requirement already satisfied: urllib3<1.26,>=1.20; python_version >= "3.4" in /home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from botocore==1.12.249->awscli) (1.25.3)
Requirement already satisfied: python-dateutil<3.0.0,>=2.1; python_version >= "2.7" in /home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from botocore==1.12.249->awscli) (2.8.0)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from botocore==1.12.249->awscli) (0.9.4)
Requirement already satisfied: pyasn1>=0.1.3 in /home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from rsa<=3.5.0,>=3.1.2->awscli) (0.4.6)
Requirement already satisfied: six>=1.5 in /home/appuser/.pyenv/versions/3.6.5/lib/python3.6/site-packages (from python-dateutil<3.0.0,>=2.1; python_version >= "2.7"->botocore==1.12.249->awscli) (1.12.0)
Installing collected packages: botocore, awscli
  Found existing installation: botocore 1.12.247
    Uninstalling botocore-1.12.247:
      Successfully uninstalled botocore-1.12.247
Successfully installed awscli-1.16.259 botocore-1.12.249
```

### 再度ツールを使用してみる

```
$ python -V
Python 3.6.5
$ bash -x ObjectStorageUpload.sh feature/20191019
Suucess Upload Completed !!
```
* 成功！