はじめに
- Mac環境に AWS CLI をインストールする機会があったので、その備忘録です。
動作環境
- macOS Catalina 10.15.7
手順
AWS CLI のインストール
- インストーラをダウンロードします。
- DLしたインストーラ(pkgファイル)を実行し、インストールします(全てデフォルト設定でOK)。
- インストールを確認します。
shell
$ which aws
# → /usr/local/bin/aws
$ aws --version
# → aws-cli/2.1.32 Python/3.8.8 Darwin/19.6.0 exe/x86_64 prompt/off
AWS CLIの設定
-
aws configure
コマンドで実行ユーザの認証情報(プロファイル)を紐付けます。
shell
$ aws configure
# IAMユーザのアクセスキー設定
AWS Access Key ID [None]: xxxxxxxx
# IAMユーザのシークレットアクセスキー設定
AWS Secret Access Key [None]: yyyyyyyy
# リージョン設定:東京
Default region name [None]: ap-northeast-1
# 出力設定:json
Default output format [None]: json
- ホームディレクトリ直下に
.aws
フォルダが作成され、そのフォルダ内にconfig
ファイルとcredentials
ファイルが出力されます。
.aws\config
[default]
region = ap-northeast-1
output = json
.aws\credentials
[default]
aws_access_key_id = xxxxxxxx
aws_secret_access_key = yyyyyyyy
- CLIに紐付いているプロファイルを確認します。
shell
$ aws configure list
# Name Value Type Location
# ---- ----- ---- --------
# profile <not set> None None
# access_key ****************xxxx shared-credentials-file
# secret_key ****************yyyy shared-credentials-file
# region ap-northeast-1 config-file ~/.aws/config
- CLIのプロファイルを一時的に変更してみます。
.aws\config
[default]
region = ap-northeast-1
output = json
[profile user1]
region = ap-northeast-1
output = json
.aws\credentials
[default]
aws_access_key_id = xxxxxxxx
aws_secret_access_key = yyyyyyyy
[user1]
aws_access_key_id = zzzzzzzz
aws_secret_access_key = aaaaaaaa
shell
$ aws configure list --profile user1
# Name Value Type Location
# ---- ----- ---- --------
# profile <not set> None None
# access_key ****************zzzz shared-credentials-file
# secret_key ****************aaaa shared-credentials-file
# region ap-northeast-1 config-file ~/.aws/config