Is there a way to list available/configured AWS CLI profiles?

17

2

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

Ville

Posted 2017-10-18T18:42:27.550

Reputation: 1 692

Answers

12

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

Ville

Posted 2017-10-18T18:42:27.550

Reputation: 1 692

9

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

thedanotto

Posted 2017-10-18T18:42:27.550

Reputation: 211