54

Is there a way to list available/configured AWS CLI profiles, other than parsing ~/.aws/config and/or ~/.aws/credentials for profile names?

5 Answers 5

65

You can list profiles in your aws config/credential files using list-profiles:

aws configure list-profiles

This is working for me with aws-cli version 2.0.8.

3
  • 4
    It's new in AWS CLI 2.x.
    – Ville
    Apr 22, 2020 at 23:30
  • 3
    this should be bumped as as the answer in 2020
    – tom
    Jul 16, 2020 at 16:17
  • Bumped (in 2022 :)
    – Ville
    Oct 5, 2022 at 18:06
15

(Answering my own question.)

No, there is not.

I wrote two scripts that include the parsing I ended up using. For anyone interested, they're available in two GitHub repositories:

awscli-mfa and aws-scripts

There are two related blog articles : "AWS CLI Key Rotation Script for IAM Users revisited", and "Easy MFA and Profile Switching in AWS CLI".

(update 2019-01-27: the blog article "Easy MFA and Profile Switching in AWS CLI" is out of date as it refers to the awscli-mfa.sh script version 1.x while the rewritten 2.x has been released. An updated blog article is forthcoming, but in the meanwhile, please refer to the awscli-mfa repository documentation)

1
  • 1
    As an answer lower down states, AWS CLI v2 has aws configure list-profiles. Unfortunately, v2 is bit more tedious to install & update than v1 (as of 2020, at least)
    – Mike B
    May 27, 2020 at 6:15
14

Parsing ~/.aws/credentials was simple enough for me.

$ cat ~/.aws/credentials | grep -o '\[[^]]*\]'

=> [default] [other_profile] [other_profile2]

I also aliased the command into aws-profiles by adding the following line into my ~/.bash_profile

alias aws-profiles="cat ~/.aws/credentials | grep -o '\[[^]]*\]'"

utilizing a profile

add --profile <profile_name> to your aws command. Ex. $ aws s3 cp ~/my.pdf s3://my_bucket/my.pdf --profile other_profile2

2

If you want to parse the config file rather than credentials (which I found was more practical when using a source_profile rather than having unique credentials defined in credentials for each profile), then the following should do the trick:

cat ~/.aws/config | grep "\[profile " | sed -e 's/\[//g' -e 's/\]//g' -e 's/profile //g'

This will find all lines like this:

[profile foo]
[profile bar]

And return this:

foo
bar
0

for AWS CLI 2 there is the command

aws configure list-profiles

for AWS CLI 1 there is not a command, but if you type

aws configure list --profile

and then press tab, it will give you the names of all the profiles, then you can use the above command to inspect each profile configuration.

2
  • That has been already stated in other answer.
    – Toto
    Feb 8 at 16:42
  • I didn't notice the AWS CLI 1 part in the previous answers Feb 8 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.