1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AWS CLI プロファイルの切り替えコマンド

Last updated at Posted at 2025-07-09

この記事について

仕事上、AWSのアカウントを複数使い分けることがあります。
CLIのプロファイルの切り替え方を毎回調べているのでまとめておきます。

コマンド

設定済みのプロファイルを一覧にする

aws configure list-profiles

このコマンドで、~/.aws/config 配下に入った [profile ]の情報および ~/.aws/credentials 配下に認証情報が入っているプロファイルの情報が一覧で表示される。

余談 - ~/.aws 配下のファイルの中身

~/.aws/config

以下のようなプロファイル情報がまとまって記載されている

~/.aws/config
[profile プロファイル名]
output = 指定した表示形式(jsonなど)

~/.aws/credentials

以下のようなセキュリティ認証情報がまとまって記載されている

~/.aws/credentials
[プロファイル名]
aws_access_key_id = アクセスキーID
aws_secret_access_key = シークレット

プロファイルを切り替える

export AWS_PROFILE=プロファイル名

これで、シェルのセッション中はオプションで明示しない限り設定したプロファイル情報でコマンドが実行される。

プロファイルを新規で作成する場合

プロファイルを新規で作成する場合は、必要な権限を持つ IAM ロールを作成した上で、そのIAMロールのアクセスキーを取得した上で以下を実行する。

aws configure --profile プロファイル名

対話形式で以下の項目を聞かれるので入力する。

AWS Access Key ID [None]: AKIAxxxxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxxxxxxxxxxxxxx
Default region name [None]: ap-northeast-1
Default output format [None]: json

現在利用中のプロファイルを確認する

表形式での表示
aws configure list
指定した表示形式(json等)での表示
aws sts get-caller-identity
1
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?