AWS CLIで設定済みのプロファイル名を確認するにはaws configure list-profilesを実行する。プロファイルの設定内容まで確認する場合はaws configure listを使う。

プロファイルの一覧を表示する

aws configure list-profilesはプロファイル名を1行ずつ出力する。

$ aws configure list-profiles
default
example-staging
example-production

一覧には~/.aws/config~/.aws/credentialsの両方のプロファイルが含まれる。

設定ファイルごとのプロファイル名の書き方

~/.aws/config~/.aws/credentialsではセクション名の書き方が異なる。

~/.aws/configではプロファイル名の前にprofileを付ける。

[default]
region = ap-northeast-1

[profile example-staging]
region = ap-northeast-1

[profile example-production]
region = us-east-1

defaultだけは例外で、[profile default]ではなく[default]と書く。

~/.aws/credentialsではprofileを付けずにプロファイル名だけを書く。

[cred-only]
aws_access_key_id = [アクセスキーID]
aws_secret_access_key = [シークレットアクセスキー]

上記2つのファイルを設定した状態で実行すると、4つのプロファイルがすべて表示される。

$ aws configure list-profiles
default
example-staging
example-production
cred-only

プロファイルの設定内容を確認する

aws configure listは現在有効なプロファイルの設定内容を表示する。

$ aws configure list
NAME       : VALUE                    : TYPE             : LOCATION
profile    : <not set>                : None             : None
access_key : <not set>                : None             : None
secret_key : <not set>                : None             : None
region     : ap-northeast-1           : config-file      : ~/.aws/config

LOCATION列には設定値の取得元が表示される。設定した値が反映されない場合、どのファイルや環境変数が使われているかを確認できる。

--profileでプロファイルを指定すると、指定したプロファイルの内容を表示する。

$ aws configure list --profile example-production
NAME       : VALUE                    : TYPE             : LOCATION
profile    : example-production       : manual           : --profile
access_key : <not set>                : None             : None
secret_key : <not set>                : None             : None
region     : us-east-1                : config-file      : ~/.aws/config

環境変数AWS_PROFILEで指定した場合はTYPEenvになる。

$ AWS_PROFILE=example-production aws configure list
NAME       : VALUE                    : TYPE             : LOCATION
profile    : example-production       : env              : ['AWS_PROFILE', 'AWS_DEFAULT_PROFILE']
access_key : <not set>                : None             : None
secret_key : <not set>                : None             : None
region     : us-east-1                : config-file      : ~/.aws/config

プロファイルが一覧に表示されない場合

configで profile を付け忘れている

~/.aws/configprofileを付けずに書くと、プロファイルとして認識されない。

[no-prefix]
region = ap-northeast-1

上記の設定ではaws configure list-profilesは何も出力しない。エラーも出ないため気付きにくい。

credentialsに profile を付けている

逆に~/.aws/credentialsprofileを付けると、profileを含む文字列がプロファイル名として扱われる。

[profile wrong-in-cred]
aws_access_key_id = [アクセスキーID]
aws_secret_access_key = [シークレットアクセスキー]
$ aws configure list-profiles
profile wrong-in-cred

設定ファイルの場所が違う

設定ファイルの場所は環境変数で変更できる。意図した場所のファイルが読まれているかを確認する。

環境変数対象既定の場所
AWS_CONFIG_FILE設定ファイル~/.aws/config
AWS_SHARED_CREDENTIALS_FILE認証情報ファイル~/.aws/credentials
$ AWS_CONFIG_FILE=/path/to/config aws configure list-profiles
from-custom

sso-sessionは一覧に含まれない

IAM Identity Center(旧AWS SSO)を使う場合、~/.aws/configsso-sessionのセクションを書く。

[sso-session my-sso]
sso_start_url = https://example.awsapps.com/start
sso_region = ap-northeast-1

[profile sso-profile]
sso_session = my-sso
sso_account_id = 111122223333
sso_role_name = ReadOnly

sso-sessionはプロファイルではないため一覧には含まれない。表示されるのはprofileのセクションだけである。

$ aws configure list-profiles
sso-profile