Can I get a list of profiles that are currently defined by the aws command?

Asked 2 months ago, Updated 2 months ago, 5 views

After executing the aws command line, I want to get the Profile List Now Defined. I think I can do it if I write a little grep, but for example, every time I ssh the server, I don't bring the script and it's a bit troublesome to type grep. If aws-cli has this feature, it seems relatively easy to do, for example, by doing all kinds of operations in aws-shell.


  • Is there a command defined to get a list of available profile names that are now aws configure?

aws aws-cli

2022-09-30 13:59

3 Answers

It is slightly different from getting the list, but it refers to what is defined in the input complement of the aws command installed with pip.
After the --profile option, you can save it in Tab to see the profile name defined as follows:

$awsec2describe-instances --profile 
 default prof1 prof2

Credentials currently configured in some way, such as aws configure or AWS_DEFAULT_PROFILE, can be found in the following commands:

$awssts get-caller-identity
    "Account": "*****", 
    "UserId": "*****", 
    "Arn": "arn:aws:iam::****"

2022-09-30 13:59

You can check the contents of the configuration file by using the following command:
Among them is a list of currently configured profiles.

cat to /.aws/credentials

2022-09-30 13:59

AWS has the configuration and credentials files.Some profiles are written only in the configuration file through /.aws/config, while others are written only in the credentials file through /.aws/credentials.

You can also use the environment variable. You can also use AWS_CONFIG_FILE or AWS_SHARED_CREMENTALS_FILE to switch to another configuration or credentials file.

Therefore, looking only at through /.aws/credentials may not solve the problem.

As suggested by ksaito

$aws --profile 
 default prof1 prof2

The output is a complementary candidate, so you can get a list of questions by directly executing the complementary command.Specifically

$env COMP_LINE='aws --profile'aws_completer

I wonder if it looks like this.(env doesn't matter.)

2022-09-30 13:59

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.