If you are a boto3 user and have multiple AWS profiles defined in your shell, I am sure that you have faced this issue at least once. Boto3 loads the default profile if you don’t specify explicitly. I am trying to explain how to specify AWS profiles while using boto3.
Lets say, we want to use the profile “dev”, We have the following ways in boto3.
1. Create a new session with the profile
dev = boto3.session.Session(profile_name='dev')
2. Change the profile of the default session in code
boto3.setup_default_session(profile_name='dev')
3. Change the profile of the default session with an environment variable
$ AWS_PROFILE=dev python
We can also list the available profiles defined in our configuration
boto3.session.Session().available_profiles
Last Modified: