awscli 複数アカウント profile
aws cliを複数アカウントで使用するためのprofileの設定をしていきましょう。
以下公式サイトを参考としています。
https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-chap-getting-started.html
デフォルトで使用される設定は以下のようにしますが
1 2 3 4 5 |
$ aws configure AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY Default region name [None]: us-west-2 Default output format [None]: json |
複数アカウントで管理する場合は、以下のように--profile
オプションを使用して、プロファイル名を指定します。
1 2 3 4 5 |
$ aws configure --profile user2 AWS Access Key ID [None]: AKIAI44QH8DHBEXAMPLE AWS Secret Access Key [None]: je7MtGbClwBF/2Zp9Utk/h3yCo8nvbEXAMPLEKEY Default region name [None]: us-east-1 Default output format [None]: text |
設定したプロファイルの確認
設定したプロファイルは全て各ユーザの以下に記載されています。
1 2 3 4 |
$ cat ~/.aws/config [profile sample-config] region = us-east-1 output = json |
以下のように取得する事もできます。
1 2 3 4 5 6 7 8 |
$ aws configure list --profile sample-config Name Value Type Location ---- ----- ---- -------- profile sample-config manual --profile access_key ****************SWQA shared-credentials-file secret_key ****************lEq/ shared-credentials-file region us-east-1 config-file ~/.aws/config |
設定したプロファイルを使ってコマンドを使用する時
プロファイルを指定してコマンドを実行する時は、「–profile プロファイル名」で実行できるので便利です。
1 |
$ aws s3 ls s3://mybucket --profile sample-config |
ディスカッション
コメント一覧
まだ、コメントがありません