How do you list local profiles with boto3 from ~/.aws/.credentials and ~/.aws/.config files?

Viewed 1772

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.

1 Answers

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)
Related