環境
macOS Catalina 10.15.5
zsh
tl;dr
AWS CLIの設定切替方法と、AWS_DEFAULT_PROFILEとAWS_PROFILEの違いについて でAWSのPROFILEを切り替えようとして切り替わらなかった原因と対策
切り替わらないよ?
Valueのところが「default」から「personal」に変わっているのに、access_keyとsecret_keyが切り替わらない。
% aws configure list
Name Value Type Location
---- ----- ---- --------
profile default manual --profile
access_key ****************^-^v env
secret_key ****************^-^v env
region ap-northeast-1 env AWS_DEFAULT_REGION
% export AWS_DEFAULT_PROFILE=personal
% aws configure list
Name Value Type Location
---- ----- ---- --------
profile personal manual --profile
access_key ****************^-^v env
secret_key ****************^-^v env
region ap-northeast-1 env AWS_DEFAULT_REGION
原因
環境変数で指定されている(~/.zshrc
の export で指定している等)と、「Type = env」で切り替わらない
対策
① ~/.zshrc
のexport部分をコメントアウト
② 既存の値を unset
unset AWS_DEFAULT_REGION
unset AWS_ACCESS_KEY_ID
unset AWS_SECRET_ACCESS_KEY
解決
% aws configure list
Name Value Type Location
---- ----- ---- --------
profile default manual --profile
access_key ****************^-^v shared-credentials-file
secret_key ****************^-^v shared-credentials-file
region ap-northeast-1 config-file ~/.aws/config
% export AWS_DEFAULT_PROFILE=personal
% aws configure list
Name Value Type Location
---- ----- ---- --------
profile personal manual --profile
access_key ****************;^-^ shared-credentials-file
secret_key ****************;^-^ shared-credentials-file
region ap-northeast-1 config-file ~/.aws/config
「Type = shared-credentials-file」になっていると、 ~/.aws/credentials や ~/.aws/config から値を取得してくれる。(環境変数にAWS_ACCESS_KEY_ID
やAWS_SECRET_ACCESS_KEY
が設定されているうちは、そちらを優先的に参照するらしい)