Describe the bug
boto3.Session() looks at AWS_PROFILE but ignores it if there are credentials specified in the environment.
Using boto3.Session(profile_name=os.environ['AWS_PROFILE']) fixes the issue but this should not be necessary.
Regression Issue
Expected Behavior
I expect boto3.Session() to use the credentials provided by the SSO profile specified via AWS_PROFILE instead of the inline credentials.
Current Behavior
If the following variables are set the AWS_PROFILE is not used even though boto3.Session().profile_name will show what is set in AWS_PROFILE
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN
Reproduction Steps
If I set AWS_PROFILE=FOO, startup python and run
import boto3
session = boto3.Session()
print(session.profile_name)
It will print FOO and I will see the details of my FOO session in session.client('sts').get_caller_identity() as expect.
Note: the FOO profile is an AWS SSO profile.
Now if I paste in credentials for a different user
export AWS_ACCESS_KEY_ID="the key"
export AWS_SECRET_ACCESS_KEY="the secret"
export AWS_SESSION_TOKEN="the session"
and re-run
AWS_PROFILE=FOO python
and in python run
import boto3
session = boto3.Session()
print(session.profile_name)
it will print "FOO" but this profile will not be used by boto3. it uses the credentials from the 3 AWS variables instead.
This is confirmed by running session.client('sts').get_caller_identity()
Now, if I instead create the session with the profile name
session = boto3.Session(profile_name=os.environ['AWS_PROFILE'])
it will now use the profile instead of the AWS_ACCESS_KEY_ID/SECRET/SESSION.
Considering that boto3.Session().profile_name correctly picks up the name from AWS_PROFILE it would seem that it should then use those credentials.
Possible Solution
No response
Additional Information/Context
No response
SDK version used
aws-cli/2.30.2, boto3/1.42.6 botocore/1.42.6
Environment details (OS name and version, etc.)
al2023 and ubuntu 22
Describe the bug
boto3.Session() looks at AWS_PROFILE but ignores it if there are credentials specified in the environment.
Using boto3.Session(profile_name=os.environ['AWS_PROFILE']) fixes the issue but this should not be necessary.
Regression Issue
Expected Behavior
I expect boto3.Session() to use the credentials provided by the SSO profile specified via AWS_PROFILE instead of the inline credentials.
Current Behavior
If the following variables are set the AWS_PROFILE is not used even though boto3.Session().profile_name will show what is set in AWS_PROFILE
AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_SESSION_TOKEN
Reproduction Steps
If I set AWS_PROFILE=FOO, startup python and run
It will print FOO and I will see the details of my FOO session in session.client('sts').get_caller_identity() as expect.
Note: the FOO profile is an AWS SSO profile.
Now if I paste in credentials for a different user
and re-run
AWS_PROFILE=FOO pythonand in python run
it will print "FOO" but this profile will not be used by boto3. it uses the credentials from the 3 AWS variables instead.
This is confirmed by running
session.client('sts').get_caller_identity()Now, if I instead create the session with the profile name
session = boto3.Session(profile_name=os.environ['AWS_PROFILE'])it will now use the profile instead of the AWS_ACCESS_KEY_ID/SECRET/SESSION.
Considering that boto3.Session().profile_name correctly picks up the name from AWS_PROFILE it would seem that it should then use those credentials.
Possible Solution
No response
Additional Information/Context
No response
SDK version used
aws-cli/2.30.2, boto3/1.42.6 botocore/1.42.6
Environment details (OS name and version, etc.)
al2023 and ubuntu 22