2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【Python】boto3でprofileが参照できずにThe config profile () could not be foundとなる

Posted at

はじめに

PythonでAWS SESのmockをしたテストを書こうとしたところ、profile参照のエラーに遭遇したので解決方法を簡単にまとめてみます。

バージョンなど

  • Python 3.9
  • boto3 1.26.137
  • moto 4.2.5

エラー

 botocore.exceptions.ProfileNotFound: The config profile () could not be found

該当コード

import pytest
from moto import mock_ses
import boto3

@mock_ses
def test_send_email():
    session = boto3.Session(profile_name='hoge')
    ses = session.client('ses', region_name='ap-northeast-1')
 

原因

boto3.Sessionの引数にprofile_nameを指定していたが、コンテナを起動時にAWS_PROFILEが空になっていたことが原因でした。

解決方法

参照しているプロファイルが正しいことを確認

$ echo $AWS_PROFILE

プロファイルを追加する場合は以下を実行して情報を追加

vi ~/.aws/credentials

参照したいプロファイルに切り替える

$ export AWS_PROFILE=hoge

これでSESのmockに成功し、テストを実行できました。mockなのでAWS認証情報はダミーで良いのですが、ライブラリがprofileを参照しにいってしまうため、参照できるようにしてあげる必要があります。

おわりに

profileを追加しても切り替えないと参照できない点にも注意が必要でした。

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?