0
1

More than 3 years have passed since last update.

aws configure profileはenvの前に無力

Last updated at Posted at 2020-07-04

環境

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_IDAWS_SECRET_ACCESS_KEYが設定されているうちは、そちらを優先的に参照するらしい)

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1