I would like to list all of my local profiles using boto3, as I think boto3 is not picking up my credentials correctly.
I have tried the following:
import boto3
boto3.Session.available_profiles
Which doesn't give me a list, but a property object.
The config file is located at ~/. aws/config on Linux or macOS, or at C:\Users\ USERNAME \. aws\config on Windows. This file contains the configuration settings for the default profile and any named profiles.
You can interact with any AWS service using Boto3 when you're programming with python if you have the access and the appropriate credentials. You can specify credentials in boto3 using session = boto3. Session(aws_access_key_id= '<your_access_key_id>' , aws_secret_access_key= '<your_secret_access_key>' ) .
Boto3 credentials can be configured in multiple ways. Regardless of the source or sources that you choose, you must have both AWS credentials and an AWS Region set in order to make requests. If you have the AWS CLI, then you can use its interactive configure command to set up your credentials and default region:
Boto3 will look in several locations when searching for credentials. The mechanism in which Boto3 looks for credentials is to search through a list of possible locations and stop as soon as it finds credentials. The order in which Boto3 searches for credentials is: Passing credentials as parameters in the boto.client()method
Boto3 is an AWS SDK for python. You can interact with any AWS service using Boto3 when you’re programming with python if you have the access and the appropriate credentials. You can specify credentials when connecting to AWS in four different ways. Passing credentials as parameters
The AWS CLI can also read credentials from the config file. You can keep all of your profile settings in a single file. If there are ever credentials in both locations for a profile (say you used aws configure to update the profile's keys), the keys in the credentials file take precedence.
You might want to use awscli
instead of boto3
to list your profiles.
aws configure list
This should output something like this:
Name Value Type Location
---- ----- ---- --------
profile <not set> None None
access_key ****************ABCD config_file ~/.aws/config
secret_key ****************ABCD config_file ~/.aws/config
region us-west-2 env AWS_DEFAULT_REGION
As for boto3
, try this:
for profile in boto3.session.Session().available_profiles:
print(profile)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With