LoginSignup
1
1

More than 5 years have passed since last update.

AWS Command Line Interface (aws-cli) でプロファイルを切り替える

Posted at

いつも切り替えのための環境変数名を忘れてしまうので記録しておきます。

手順

プロファイルを作成する

aws configure実行時に--profileオプションにプロファイル名を付与して渡します。

$ aws configure --profile sample-profile

~/.aws/credentials~/.aws/configにプロファイルが追加されます。

プロファイルの切り替え方

configure実行時と同様に、awsコマンドへ--profileオプションを渡します。

$ aws ec2 describe-instances --profile sample-profile

また、オプションだけでなくAWS_DEFAULT_PROFILE環境変数でプロファイルを切り替えることも可能です。

$ export AWS_DEFAULT_PROFILE=sample-profile
$ aws ec2 describe-instances

ただし、AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYが設定されていると、そちらを優先しますので注意してください。

参考

1
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
1
1