62

Given I have the following config file:

[default]
aws_access_key_id=default_access_key
aws_secret_access_key=default_secret_key

[profile testing]
aws_access_key_id=testing_access_key
aws_secret_access_key=testing_secret_key
region=us-west-2

And given the name of my default profile is foo

What CLI commands do I need to type in to get the name of my default profile. Something like:

$ aws describe-default-profile

{
    ...
    "default_profile_name": 'foo'
}

Or list all profiles and it ouputs the default too:

$ aws list-all-profiles

{
    [{
        ...
        profile_name: 'foo',
        "is_default": true
    }]
}

There is a get-instance-profile on iam (docs), but it requires the name of the profile be specified:

$ aws iam get-instance-profile --instance-profile-name ExampleInstanceProfile
Green
  • 28,742
  • 61
  • 158
  • 247
  • Are you asking what an instance profile is? – helloV Nov 04 '16 at 06:03
  • you can always get your AWS_DEFAULT_PROFILE from environment variables. Generally the default profile is tagged with name "default" unless you specify another profile in environment variables. – Ali Nov 04 '16 at 06:41

4 Answers4

111

You can run aws configure list to list your current profile

List the AWS CLI configuration data. This command will show you the current configuration data. For each configuration item, it will show you the value, where the configuration value was retrieved, and the configuration variable name. For example, if you provide the AWS region in an environment variable, this command will show you the name of the region you've configured, it will tell you that this value came from an environment variable, and it will tell you the name of the environment variable.

To show your current configuration values:

      $ aws configure list
            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

If you want to review your configuration for a specific profile, you can run aws configure list --profile foo

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
34

Since version 2 you can use:

$ aws configure list-profiles
default
test

To show all the available profiles.

https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html

Alberto Rojas
  • 549
  • 5
  • 5
4

There are no commands in the AWS Command-Line Interface (CLI) for viewing the profile. You would need to look at the configuration files for this information.

The aws iam get-instance-profile command is unrelated to the AWS CLI. It is a way of assigning a Role to an Amazon EC2 instance.

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
  • If you are on linux, you can: `grep '^[[]profile' <~/.aws/config | awk '{print $2}' | sed 's/]$//'` – M. Ayers Sep 06 '17 at 21:25
  • This assumes you are using the default aws config dir location. You can also use `sed -n 's#^\[\(.*\)\]#\1#p' ~/.aws/credentials | sort -u`. On macOS change `sed` to `gsed` which you can get with `brew install gnu-sed`. – Mike D Jan 31 '18 at 17:35
2

The one and only

aws sts get-caller-identity
Shady Smaoui
  • 867
  • 9
  • 11