🔑
boto3をprofile指定なしで使う場合はAWS Common Runtimeが必要
boto3をprofile指定なしで使う場合はAWS Common Runtime(botocore[crt])のインストールが必要
プロファイル指定をせずにboto3を実行する場合。
aws loginさえしちゃえばboto3使えるかな〜と思ったけどエラー。
AWS Common Runtime(botocore[crt])のインストールが必要でした。
pip install "botocore[crt]"
再現確認
profile指定なしで boto3 を実行する。
import boto3
s3_client = boto3.client('s3')
response = s3_client.list_buckets()
print('Existing buckets:')
以下のエラーが発生します。
% python awslogin-test.py
Traceback (most recent call last):
File "/myapp/awslogin-test.py", line 3, in <module>
s3_client = boto3.client('s3')
^^^^^^^^^^^^^^^^^^
File "/myapp/.venv/lib/python3.12/site-packages/boto3/__init__.py", line 93, in client
return _get_default_session().client(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/myapp/.venv/lib/python3.12/site-packages/boto3/session.py", line 337, in client
return self._session.create_client(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/myapp/.venv/lib/python3.12/site-packages/botocore/context.py", line 123, in wrapper
return func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/myapp/.venv/lib/python3.12/site-packages/botocore/session.py", line 986, in create_client
credentials = self.get_credentials()
^^^^^^^^^^^^^^^^^^^^^^
File "/myapp/.venv/lib/python3.12/site-packages/botocore/session.py", line 522, in get_credentials
).load_credentials()
^^^^^^^^^^^^^^^^^^
File "/myapp/.venv/lib/python3.12/site-packages/botocore/credentials.py", line 2239, in load_credentials
creds = provider.load()
^^^^^^^^^^^^^^^
File "/myapp/.venv/lib/python3.12/site-packages/botocore/credentials.py", line 2750, in load
raise MissingDependencyException(
botocore.exceptions.MissingDependencyException: Missing Dependency: Using the login credential provider requires an additional dependency. You will need to pip install "botocore[crt]" before proceeding.
You will need to pip install "botocore[crt]" before proceeding. だそうです。
解決するために、botocore[crt]をインストール。
pip install "botocore[crt]"
インストール後、問題なく実行できるようになりました。
参考:boto3 documentation
補足:profileを指定する場合はAWS Common Runtime(botocore[crt])は不要
aws loginであっても、下記のように boto3 の session で profile を指定している場合は、AWS Common Runtime は不要です。
import boto3
session = boto3.Session(profile_name='temporary')
s3_client = session.client('s3')
response = s3_client.list_buckets()
print('Existing buckets:')
Discussion