webmaster-kazu.com

テクノロジー・データ分析・実践ログ・その他

【Python】テストで AWS サービスを簡単にモックアウトできる「moto」のインストール

カテゴリ: Python【初歩から現場実務的なもの】

テストで AWS サービスを簡単にモックアウトできる「moto」のインストールについて解説しています。なお、モックアウトは、製品やシステムのプロトタイプ開発段階で使用される試作品のことを指しています。

「moto(https://github.com/getmoto/moto)」は、AWS インフラストラクチャに基づいたテストを簡単にモックアウトできます。なお、Pythonのバージョンが3.7以上でのインストールが必要。

■Python

今回のPythonのバージョンは、「3.8.5」を使用しています。(Windows11)

■motoをインストールする

motoをインストールを行いますが、今回はpipを経由してインストールを行うので、まずWindowsのコマンドプロンプトを起動します。

pip install moto

起動後、上記のコマンドを入力し、Enterキーを押します。

なお、今回は、pythonランチャーを使用しており、Python Version 3.8.5にインストールを行うために、バージョンの切り替えを行います。

py -3.8 -m pip install moto

切り替えるために、上記のコマンドを入力し、Enterキーを押します。

Defaulting to user installation because normal site-packages is not writeable

Collecting moto

Downloading moto-4.1.13-py2.py3-none-any.whl (3.1 MB)

|████████████████████████████████| 3.1 MB 3.3 MB/s

Collecting Jinja2>=2.10.1

Using cached Jinja2-3.1.2-py3-none-any.whl (133 kB)

Requirement already satisfied: requests>=2.5 in c:\users\user_\appdata\roaming\python\python38\site-packages (from moto) (2.31.0)

Requirement already satisfied: python-dateutil<3.0.0,>=2.1 in c:\users\user_\appdata\roaming\python\python38\site-packages (from moto) (2.8.2)

Collecting werkzeug!=2.2.0,!=2.2.1,>=0.5

Using cached Werkzeug-2.3.6-py3-none-any.whl (242 kB)

Collecting botocore>=1.12.201

Downloading botocore-1.31.3-py3-none-any.whl (11.0 MB)

|████████████████████████████████| 11.0 MB 3.3 MB/s

Collecting boto3>=1.9.201

Downloading boto3-1.28.3-py3-none-any.whl (135 kB)

|████████████████████████████████| 135 kB 6.4 MB/s

Collecting cryptography>=3.3.1

Downloading cryptography-41.0.2-cp37-abi3-win_amd64.whl (2.6 MB)

|████████████████████████████████| 2.6 MB 6.8 MB/s

Collecting responses>=0.13.0

Downloading responses-0.23.1-py3-none-any.whl (52 kB)

|████████████████████████████████| 52 kB 3.8 MB/s

Collecting xmltodict

Downloading xmltodict-0.13.0-py2.py3-none-any.whl (10.0 kB)

Collecting jmespath<2.0.0,>=0.7.1

Downloading jmespath-1.0.1-py3-none-any.whl (20 kB)

Collecting s3transfer<0.7.0,>=0.6.0

Downloading s3transfer-0.6.1-py3-none-any.whl (79 kB)

|████████████████████████████████| 79 kB 5.5 MB/s

Collecting urllib3<1.27,>=1.25.4

Using cached urllib3-1.26.16-py2.py3-none-any.whl (143 kB)

Collecting cffi>=1.12

Using cached cffi-1.15.1-cp38-cp38-win_amd64.whl (178 kB)

Collecting pycparser

Using cached pycparser-2.21-py2.py3-none-any.whl (118 kB)

Collecting MarkupSafe>=2.0

Using cached MarkupSafe-2.1.3-cp38-cp38-win_amd64.whl (17 kB)

Requirement already satisfied: six>=1.5 in c:\users\user_\appdata\roaming\python\python38\site-packages (from python-dateutil<3.0.0,>=2.1->moto) (1.16.0)

Requirement already satisfied: idna<4,>=2.5 in c:\users\user_\appdata\roaming\python\python38\site-packages (from requests>=2.5->moto) (3.4)

Requirement already satisfied: certifi>=2017.4.17 in c:\users\user_\appdata\roaming\python\python38\site-packages (from requests>=2.5->moto) (2023.5.7)

Requirement already satisfied: charset-normalizer<4,>=2 in c:\users\user_\appdata\roaming\python\python38\site-packages (from requests>=2.5->moto) (3.2.0)

Collecting types-PyYAML

Downloading types_PyYAML-6.0.12.10-py3-none-any.whl (14 kB)

Requirement already satisfied: pyyaml in c:\users\user_\appdata\roaming\python\python38\site-packages (from responses>=0.13.0->moto) (6.0)

Installing collected packages: urllib3, jmespath, pycparser, botocore, types-PyYAML, s3transfer, MarkupSafe, cffi, xmltodict, werkzeug, responses, Jinja2, cryptography, boto3, moto

Attempting uninstall: urllib3

Found existing installation: urllib3 2.0.3

Uninstalling urllib3-2.0.3:

Successfully uninstalled urllib3-2.0.3

WARNING: The script moto_server.exe is installed in 'C:\Users\user_\AppData\Roaming\Python\Python38\Scripts' 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 Jinja2-3.1.2 MarkupSafe-2.1.3 boto3-1.28.3 botocore-1.31.3 cffi-1.15.1 cryptography-41.0.2 jmespath-1.0.1 moto-4.1.13 pycparser-2.21 responses-0.23.1 s3transfer-0.6.1 types-PyYAML-6.0.12.10 urllib3-1.26.16 werkzeug-2.3.6 xmltodict-0.13.0

WARNING: You are using pip version 21.1.1; however, version 23.2 is available.

You should consider upgrading via the 'C:\Program Files\Python38\python.exe -m pip install --upgrade pip' command.

Enterキーを押すと、インストールが開始され、上記のように「Successfully installed」と表示されます。これが表示されれば、motoが正常にインストールされたことになりますが、「WARNING」と表示されました。「WARNING」はエラーではなく警告で、インストールは行われているので、今回は一旦無視しています。

なお、今回はmotoのバージョン4.1.13をインストールしました。